Skip to content

Commit 5b9a330

Browse files
authored
chore(deps): ts-jest update (ionic-team#3704)
1 parent 9960047 commit 5b9a330

49 files changed

Lines changed: 567 additions & 412 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

jest.config.base.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
module.exports = {
2-
transform: {
3-
"^.+\\.tsx?$": "ts-jest"
2+
preset: 'ts-jest',
3+
globals: {
4+
'ts-jest': {
5+
diagnostics: {
6+
// warnOnly: true,
7+
},
8+
tsConfig: {
9+
types: [
10+
"node",
11+
"jest",
12+
],
13+
},
14+
},
415
},
5-
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
6-
moduleFileExtensions: [
7-
"ts",
8-
"tsx",
9-
"js",
10-
"jsx",
11-
"json"
12-
],
1316
};

packages/@ionic/cli-framework/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint": "tslint --config tslint.js --project tsconfig.json",
1515
"build": "npm run clean && tsc",
1616
"watch": "tsc -w --preserveWatchOutput",
17-
"test": "jest",
17+
"test": "jest --maxWorkers=4",
1818
"prepublishOnly": "npm run build",
1919
"cli-scripts:pre-commit": "lint-staged"
2020
},
@@ -49,6 +49,7 @@
4949
"@types/cross-spawn": "^6.0.0",
5050
"@types/debug": "0.0.31",
5151
"@types/inquirer": "0.0.43",
52+
"@types/jest": "^23.3.5",
5253
"@types/lodash": "^4.14.104",
5354
"@types/minimist": "^1.2.0",
5455
"@types/node": "^6.0.101",
@@ -61,7 +62,7 @@
6162
"jest": "^23.0.1",
6263
"jest-cli": "^23.0.1",
6364
"lint-staged": "^7.2.0",
64-
"ts-jest": "~23.1.0",
65+
"ts-jest": "^23.10.1",
6566
"tslint": "^5.9.1",
6667
"typescript": "~3.1.1"
6768
}

packages/@ionic/cli-framework/src/lib/__tests__/command.ts

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import {
2-
Command,
3-
CommandMap,
4-
CommandMapDefault,
5-
Namespace,
6-
NamespaceMap,
7-
generateCommandPath,
8-
} from '../command';
1+
import { CommandMetadata } from '../../definitions';
2+
import { Command, CommandMap, CommandMapDefault, Namespace, NamespaceMap, generateCommandPath } from '../command';
93

104
class MyNamespace extends Namespace {
11-
async getMetadata() {
12-
return { name: 'my' };
5+
async getMetadata(): Promise<CommandMetadata> {
6+
return {
7+
name: 'my',
8+
summary: '',
9+
};
1310
}
1411

15-
async getNamespaces() {
12+
async getNamespaces(): Promise<NamespaceMap> {
1613
return new NamespaceMap([
1714
['foo', async () => new FooNamespace(this)],
1815
['defns', async () => new NamespaceWithDefault(this)],
@@ -22,23 +19,29 @@ class MyNamespace extends Namespace {
2219
}
2320

2421
class NamespaceWithDefault extends Namespace {
25-
async getMetadata() {
26-
return { name: 'defns' };
22+
async getMetadata(): Promise<CommandMetadata> {
23+
return {
24+
name: 'defns',
25+
summary: '',
26+
};
2727
}
2828

29-
async getCommands() {
29+
async getCommands(): Promise<CommandMap> {
3030
return new CommandMap([
3131
[CommandMapDefault, async () => new DefaultCommand(this)],
3232
]);
3333
}
3434
}
3535

3636
class FooNamespace extends Namespace {
37-
async getMetadata() {
38-
return { name: 'foo' };
37+
async getMetadata(): Promise<CommandMetadata> {
38+
return {
39+
name: 'foo',
40+
summary: '',
41+
};
3942
}
4043

41-
async getCommands() {
44+
async getCommands(): Promise<CommandMap> {
4245
return new CommandMap([
4346
['bar', async () => new BarCommand(this)],
4447
['baz', async () => new BazCommand(this)],
@@ -48,37 +51,45 @@ class FooNamespace extends Namespace {
4851
}
4952

5053
class EmptyNamespace extends Namespace {
51-
async getMetadata() {
52-
return { name: 'empty' };
54+
async getMetadata(): Promise<CommandMetadata> {
55+
return {
56+
name: 'empty',
57+
summary: '',
58+
};
5359
}
5460
}
5561

5662
class DefaultCommand extends Command {
57-
async getMetadata() {
58-
return { name: 'def', description: '' };
63+
async getMetadata(): Promise<CommandMetadata> {
64+
return {
65+
name: 'def',
66+
summary: '',
67+
};
5968
}
69+
70+
async run() {}
6071
}
6172

6273
class BarCommand extends Command {
63-
async getMetadata() {
64-
return { name: 'bar', description: '' };
74+
async getMetadata(): Promise<CommandMetadata> {
75+
return {
76+
name: 'bar',
77+
summary: '',
78+
};
6579
}
66-
}
6780

68-
class BazCommand extends Command {
69-
async getMetadata() {
70-
return { name: 'baz', description: '' };
71-
}
81+
async run() {}
7282
}
7383

74-
class FooCommand extends Command {
75-
async getMetadata() {
84+
class BazCommand extends Command {
85+
async getMetadata(): Promise<CommandMetadata> {
7686
return {
77-
name: 'foo',
78-
type: 'global',
79-
description: '',
87+
name: 'baz',
88+
summary: '',
8089
};
8190
}
91+
92+
async run() {}
8293
}
8394

8495
describe('@ionic/cli-framework', () => {
@@ -90,7 +101,7 @@ describe('@ionic/cli-framework', () => {
90101
describe('root and parent', () => {
91102

92103
it('should have root attribute', async () => {
93-
const testNamespace = async ns => {
104+
const testNamespace = async (ns: Namespace) => {
94105
const namespaces = await ns.getNamespaces();
95106

96107
for (let [ , nsgetter ] of namespaces.entries()) {
@@ -107,7 +118,7 @@ describe('@ionic/cli-framework', () => {
107118
});
108119

109120
it('should have parent attribute', async () => {
110-
const testNamespace = async ns => {
121+
const testNamespace = async (ns: Namespace) => {
111122
const namespaces = await ns.getNamespaces();
112123

113124
for (let [ , nsgetter ] of namespaces.entries()) {
@@ -128,7 +139,7 @@ describe('@ionic/cli-framework', () => {
128139
describe('getNamespaces', () => {
129140

130141
it('should get subnamespaces', async () => {
131-
const testNamespace = async ns => {
142+
const testNamespace = async (ns: Namespace) => {
132143
const commands = await ns.getCommands();
133144
const namespaces = await ns.getNamespaces();
134145

@@ -297,7 +308,9 @@ describe('@ionic/cli-framework', () => {
297308
const ns = new MyNamespace();
298309
const result = await ns.getCommandMetadataList();
299310
const bar = result.find(c => c.command instanceof BarCommand);
300-
expect(bar).toBeDefined();
311+
if (!bar) {
312+
throw new Error('bar not defined');
313+
}
301314
expect(bar.path.length).toEqual(3);
302315
expect(bar.path[0][0]).toEqual('my');
303316
expect(bar.path[0][1]).toBe(ns);
@@ -312,11 +325,17 @@ describe('@ionic/cli-framework', () => {
312325
const result = await ns.getCommandMetadataList();
313326
expect(result.length).toEqual(3);
314327
const bar = result.find(c => c.command instanceof BarCommand);
315-
expect(bar).toBeDefined();
328+
if (!bar) {
329+
throw new Error('bar not defined');
330+
}
316331
const baz = result.find(c => c.command instanceof BazCommand);
317-
expect(baz).toBeDefined();
332+
if (!baz) {
333+
throw new Error('baz not defined');
334+
}
318335
const def = result.find(c => c.command instanceof DefaultCommand);
319-
expect(def).toBeDefined();
336+
if (!def) {
337+
throw new Error('def not defined');
338+
}
320339
expect(bar.aliases).toEqual(['my foo b']);
321340
expect(def.aliases).toEqual([]);
322341
expect(baz.aliases).toEqual([]);
@@ -333,7 +352,7 @@ describe('@ionic/cli-framework', () => {
333352
it('should get path for single namespace and command', async () => {
334353
const ns = new FooNamespace();
335354
const { obj } = await ns.locate(['bar']);
336-
const result = await generateCommandPath(obj);
355+
const result = await generateCommandPath(obj as any);
337356
expect(result.length).toEqual(2);
338357
const [ foons, barcmd ] = result;
339358
expect(foons).toBeDefined();
@@ -347,7 +366,7 @@ describe('@ionic/cli-framework', () => {
347366
it('should work back through nested namespace', async () => {
348367
const ns = new MyNamespace();
349368
const { obj } = await ns.locate(['foo', 'bar']);
350-
const result = await generateCommandPath(obj);
369+
const result = await generateCommandPath(obj as any);
351370
expect(result.length).toEqual(3);
352371
const [ rootns, foons, barcmd ] = result;
353372
expect(rootns).toEqual(['my', ns]);

packages/@ionic/cli-framework/src/lib/__tests__/config.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ describe('@ionic/cli-framework', () => {
22

33
describe('BaseConfig', () => {
44

5-
let Config, mockReadFileSync, mockMakeDirSync, mockWriteFileAtomicSync;
5+
let Config: any;
6+
let mockReadFileSync: jest.Mock;
7+
let mockMakeDirSync: jest.Mock;
8+
let mockWriteFileAtomicSync: jest.Mock;
69

7-
beforeEach(() => {
10+
beforeEach(async () => {
811
mockReadFileSync = jest.fn();
912
mockMakeDirSync = jest.fn();
1013
mockWriteFileAtomicSync = jest.fn();
@@ -13,10 +16,10 @@ describe('@ionic/cli-framework', () => {
1316
jest.mock('@ionic/utils-fs', () => ({ mkdirpSync: mockMakeDirSync }));
1417
jest.mock('write-file-atomic', () => ({ sync: mockWriteFileAtomicSync }));
1518

16-
const { BaseConfig } = require('../config');
19+
const { BaseConfig } = await import('../config');
1720

18-
Config = class extends BaseConfig {
19-
provideDefaults(c) {
21+
Config = class extends BaseConfig<any> {
22+
provideDefaults() {
2023
return {
2124
defaulted: 5,
2225
};
@@ -157,9 +160,12 @@ describe('@ionic/cli-framework', () => {
157160

158161
describe('BaseConfig with pathPrefix', () => {
159162

160-
let Config, mockReadFileSync, mockMakeDirSync, mockWriteFileAtomicSync;
163+
let Config: any;
164+
let mockReadFileSync: jest.Mock;
165+
let mockMakeDirSync: jest.Mock;
166+
let mockWriteFileAtomicSync: jest.Mock;
161167

162-
beforeEach(() => {
168+
beforeEach(async () => {
163169
mockReadFileSync = jest.fn();
164170
mockMakeDirSync = jest.fn();
165171
mockWriteFileAtomicSync = jest.fn();
@@ -168,10 +174,10 @@ describe('@ionic/cli-framework', () => {
168174
jest.mock('@ionic/utils-fs', () => ({ mkdirpSync: mockMakeDirSync }));
169175
jest.mock('write-file-atomic', () => ({ sync: mockWriteFileAtomicSync }));
170176

171-
const { BaseConfig } = require('../config');
177+
const { BaseConfig } = await import('../config');
172178

173-
Config = class extends BaseConfig {
174-
provideDefaults(c) {
179+
Config = class extends BaseConfig<any> {
180+
provideDefaults() {
175181
return {
176182
defaulted: 5,
177183
};

0 commit comments

Comments
 (0)