Skip to content

Commit 09ffe8b

Browse files
authored
Merge pull request #5 from kreuzerk/feature/migrateToJest
Feature/migrate to jest
2 parents 60c3df0 + 0407e5f commit 09ffe8b

File tree

7 files changed

+6042
-1846
lines changed

7 files changed

+6042
-1846
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ yarn-error.log*
1616
# Mac OSX Finder files.
1717
**/.DS_Store
1818
.DS_Store
19+
20+
# Coverage
21+
coverage/

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
roots: ['<rootDir>/src'],
3+
transform: {
4+
'^.+\\.tsx?$': 'ts-jest'
5+
},
6+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
7+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
8+
};

package-lock.json

Lines changed: 5990 additions & 1789 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"build:watch": "tsc -p tsconfig.json --watch",
88
"format": "prettier src/**/*.{ts,json,md} --write",
99
"format:test": "prettier src/**/*.{ts,json,md} --list-different",
10-
"test": "mocha src/**/*.spec.ts --require ts-node/register --async-only",
11-
"test:watch": "mocha src/**/*.spec.ts --require ts-node/register --watch-extensions ts --watch"
10+
"test": "jest --collectCoverage",
11+
"test:watch": "jest --watch"
1212
},
1313
"husky": {
1414
"hooks": {
@@ -30,16 +30,15 @@
3030
"typescript": "^3.8.3"
3131
},
3232
"devDependencies": {
33-
"@types/chai": "^4.2.11",
34-
"@types/mocha": "^5.2.7",
33+
"@types/jest": "^25.2.1",
3534
"@types/node": "^8.10.59",
36-
"chai": "^4.2.0",
3735
"husky": "^4.2.5",
38-
"mocha": "^7.0.0",
36+
"jest": "^25.5.2",
3937
"prettier": "^1.19.1",
4038
"pretty-quick": "^2.0.1",
41-
"ts-node": "^8.6.2",
42-
"semantic-release": "^17.0.7"
39+
"semantic-release": "^17.0.7",
40+
"ts-jest": "^25.4.0",
41+
"ts-node": "^8.6.2"
4342
},
4443
"repository": {
4544
"type": "git",

src/ng-samurai/index.spec.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as path from 'path';
2-
import { expect } from 'chai';
32
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
43
import { Schema as WorkspaceOptions } from '@schematics/angular/workspace/schema';
54
import { Schema as LibraryOptions } from '@schematics/angular/library/schema';
@@ -83,10 +82,6 @@ describe('ng-samurai', () => {
8382
.toPromise();
8483
}
8584

86-
function addModelFile(path: string, content: string) {
87-
appTree.create(path, content);
88-
}
89-
9085
function removeDefaultLibraryModule() {
9186
appTree.delete('/projects/some-lib/src/lib/some-lib.module.ts');
9287
appTree.delete('/projects/some-lib/src/lib/some-lib.component.spec.ts');
@@ -115,7 +110,7 @@ describe('ng-samurai', () => {
115110
'some-lib/src/lib/bar'
116111
]);
117112

118-
expect(topLevelPublicAPIContent).to.equal(expectedTopLevelPublicAPIContent);
113+
expect(topLevelPublicAPIContent).toEqual(expectedTopLevelPublicAPIContent);
119114
});
120115
});
121116

@@ -130,17 +125,17 @@ describe('ng-samurai', () => {
130125

131126
it('should add a public_api to foo module', async () => {
132127
const tree = await runner.runSchematicAsync('ng-samurai', {}, appTree).toPromise();
133-
expect(tree.exists('/projects/some-lib/src/lib/foo/public-api.ts')).to.be.true;
128+
expect(tree.exists('/projects/some-lib/src/lib/foo/public-api.ts')).toBe(true);
134129
});
135130

136131
it('should add a public_api to bar module', async () => {
137132
const tree = await runner.runSchematicAsync('ng-samurai', {}, appTree).toPromise();
138-
expect(tree.exists('/projects/some-lib/src/lib/bar/public-api.ts')).to.be.true;
133+
expect(tree.exists('/projects/some-lib/src/lib/bar/public-api.ts')).toBe(true);
139134
});
140135

141136
it('should not add a public_api to baz module', async () => {
142137
const tree = await runner.runSchematicAsync('ng-samurai', {}, appTree).toPromise();
143-
expect(tree.exists('/projects/some-lib/src/lib/bar/baz/public-api.ts')).not.to.be.true;
138+
expect(tree.exists('/projects/some-lib/src/lib/bar/baz/public-api.ts')).not.toBe(true);
144139
});
145140

146141
it('should export foo.component.ts and foo.module.ts from foos public-api', async () => {
@@ -151,7 +146,7 @@ describe('ng-samurai', () => {
151146
expectedFilesIncludedInPublicAPI
152147
);
153148

154-
expect(publicAPI).to.equal(expectedFileContent);
149+
expect(publicAPI).toEqual(expectedFileContent);
155150
});
156151

157152
it('should export bar.component.ts, bar.module.ts, bar.model and baz.component.ts from bars public-api', async () => {
@@ -167,46 +162,46 @@ describe('ng-samurai', () => {
167162
expectedFilesIncludedInPublicAPI
168163
);
169164

170-
expect(publicAPI).to.equal(expectedFileContent);
165+
expect(publicAPI).toEqual(expectedFileContent);
171166
});
172167
});
173168
});
174169

175170
describe('index.ts', () => {
176171
it('should add an index.ts to foo module', async () => {
177172
const tree = await runner.runSchematicAsync('ng-samurai', {}, appTree).toPromise();
178-
expect(tree.exists('/projects/some-lib/src/lib/foo/index.ts')).to.be.true;
173+
expect(tree.exists('/projects/some-lib/src/lib/foo/index.ts')).toBe(true);
179174
});
180175

181176
it('should add export everything from public-api inside the index.ts of foo', async () => {
182177
const tree = await runner.runSchematicAsync('ng-samurai', {}, appTree).toPromise();
183-
expect(tree.read('/projects/some-lib/src/lib/foo/index.ts').toString()).to.equal(
178+
expect(tree.read('/projects/some-lib/src/lib/foo/index.ts').toString()).toEqual(
184179
"export * from './public-api';\n"
185180
);
186181
});
187182

188183
it('should add an index.ts bar module', async () => {
189184
const tree = await runner.runSchematicAsync('ng-samurai', {}, appTree).toPromise();
190-
expect(tree.exists('/projects/some-lib/src/lib/bar/index.ts')).to.be.true;
185+
expect(tree.exists('/projects/some-lib/src/lib/bar/index.ts')).toBe(true);
191186
});
192187

193188
it('should add export everything from public-api inside the index.ts of bar', async () => {
194189
const tree = await runner.runSchematicAsync('ng-samurai', {}, appTree).toPromise();
195-
expect(tree.read('/projects/some-lib/src/lib/bar/index.ts').toString()).to.equal(
190+
expect(tree.read('/projects/some-lib/src/lib/bar/index.ts').toString()).toEqual(
196191
"export * from './public-api';\n"
197192
);
198193
});
199194

200195
it('should not add an index.ts to baz module', async () => {
201196
const tree = await runner.runSchematicAsync('ng-samurai', {}, appTree).toPromise();
202-
expect(tree.exists('/projects/some-lib/src/lib/bar/baz/index.ts')).not.to.be.true;
197+
expect(tree.exists('/projects/some-lib/src/lib/bar/baz/index.ts')).not.toBe(true);
203198
});
204199
});
205200

206201
describe('package.json', () => {
207202
it('should add an index.ts to foo module', async () => {
208203
const tree = await runner.runSchematicAsync('ng-samurai', {}, appTree).toPromise();
209-
expect(tree.exists('/projects/some-lib/src/lib/foo/package.json')).to.be.true;
204+
expect(tree.exists('/projects/some-lib/src/lib/foo/package.json')).toBe(true);
210205
});
211206

212207
it('should add the correct config to the package.json of foo subentry', async () => {
@@ -221,12 +216,12 @@ describe('ng-samurai', () => {
221216
const subEntryConfig = JSON.parse(
222217
tree.read('/projects/some-lib/src/lib/foo/package.json').toString()
223218
);
224-
expect(subEntryConfig).to.eql(expectedSubentryConfig);
219+
expect(subEntryConfig).toEqual(expectedSubentryConfig);
225220
});
226221

227222
it('should add an packag.json to bar module', async () => {
228223
const tree = await runner.runSchematicAsync('ng-samurai', {}, appTree).toPromise();
229-
expect(tree.exists('/projects/some-lib/src/lib/bar/package.json')).to.be.true;
224+
expect(tree.exists('/projects/some-lib/src/lib/bar/package.json')).toBe(true);
230225
});
231226

232227
it('should add the correct config to the package.json of bar subentry', async () => {
@@ -241,12 +236,12 @@ describe('ng-samurai', () => {
241236
const subEntryConfig = JSON.parse(
242237
tree.read('/projects/some-lib/src/lib/bar/package.json').toString()
243238
);
244-
expect(subEntryConfig).to.eql(expectedSubentryConfig);
239+
expect(subEntryConfig).toEqual(expectedSubentryConfig);
245240
});
246241

247242
it('should not add a package.json to baz module', async () => {
248243
const tree = await runner.runSchematicAsync('ng-samurai', {}, appTree).toPromise();
249-
expect(tree.exists('/projects/some-lib/src/lib/bar/baz/package.json')).not.to.be.true;
244+
expect(tree.exists('/projects/some-lib/src/lib/bar/baz/package.json')).not.toBe(true);
250245
});
251246
});
252247

@@ -293,7 +288,7 @@ describe('ng-samurai', () => {
293288
'/projects/some-lib/src/lib/bar/bar.module.ts'
294289
);
295290

296-
expect(moduleContentAfterSchematics).to.equal(expectedModuleContent);
291+
expect(moduleContentAfterSchematics).toEqual(expectedModuleContent);
297292
});
298293

299294
it('should not update the baz components content since the import paths do not need to be updated', async () => {
@@ -306,7 +301,7 @@ describe('ng-samurai', () => {
306301
'/projects/some-lib/src/lib/bar/baz/baz.component.ts'
307302
);
308303

309-
expect(componentContentAfterSchematics).to.equal(expectedComponentContent);
304+
expect(componentContentAfterSchematics).toEqual(expectedComponentContent);
310305
});
311306
});
312307

@@ -326,7 +321,7 @@ describe('ng-samurai', () => {
326321
};
327322

328323
const paths = tsconfigContent.compilerOptions.paths;
329-
expect(paths).to.eql(expectedPaths);
324+
expect(paths).toEqual(expectedPaths);
330325
});
331326

332327
it('should add paths to the tsconfig.json even if no path exist', async () => {
@@ -338,7 +333,7 @@ describe('ng-samurai', () => {
338333
};
339334

340335
const paths = tsconfigContent.compilerOptions.paths;
341-
expect(paths).to.eql(expectedPaths);
336+
expect(paths).toEqual(expectedPaths);
342337
});
343338
});
344339
});

src/submodule/index.spec.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as path from 'path';
2-
import { expect } from 'chai';
32
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
43
import { Style, Schema as ApplicationOptions } from '@schematics/angular/application/schema';
54
import { Schema as LibraryOptions } from '@schematics/angular/library/schema';
@@ -52,30 +51,32 @@ describe('submodule', () => {
5251

5352
const tree = await runner.runSchematicAsync('submodule', options, appTree).toPromise();
5453

55-
expect(tree.files.includes('/projects/some-lib/src/lib/path/to/customer/customer.component.ts'))
56-
.to.be.true;
54+
expect(
55+
tree.files.includes('/projects/some-lib/src/lib/path/to/customer/customer.component.ts')
56+
).toBe(true);
5757
});
5858

5959
it('should generate a CustomerModule and add a CustomerComponent', async () => {
6060
const options = { ...defaultOptions };
6161

6262
const tree = await runner.runSchematicAsync('submodule', options, appTree).toPromise();
6363

64-
expect(tree.files.includes('/projects/some-lib/src/lib/path/to/customer/customer.module.ts')).to
65-
.be.true;
64+
expect(
65+
tree.files.includes('/projects/some-lib/src/lib/path/to/customer/customer.module.ts')
66+
).toBe(true);
6667
expect(
6768
tree
6869
.readContent('/projects/some-lib/src/lib/path/to/customer/customer.module.ts')
6970
.includes('CustomerComponent')
70-
).to.be.true;
71+
).toBe(true);
7172
});
7273

7374
it('should export everything from public-api inside index.ts', async () => {
7475
const options = { ...defaultOptions };
7576
const expectedContent = "export * from './public-api';\n";
7677

7778
const tree = await runner.runSchematicAsync('submodule', options, appTree).toPromise();
78-
expect(tree.readContent('/projects/some-lib/src/lib/path/to/customer/index.ts')).to.equal(
79+
expect(tree.readContent('/projects/some-lib/src/lib/path/to/customer/index.ts')).toEqual(
7980
expectedContent
8081
);
8182
});
@@ -86,7 +87,7 @@ describe('submodule', () => {
8687
"export * from './customer.module';\nexport * from './customer.component';\n";
8788

8889
const tree = await runner.runSchematicAsync('submodule', options, appTree).toPromise();
89-
expect(tree.readContent('/projects/some-lib/src/lib/path/to/customer/public-api.ts')).to.equal(
90+
expect(tree.readContent('/projects/some-lib/src/lib/path/to/customer/public-api.ts')).toEqual(
9091
expectedContent
9192
);
9293
});
@@ -104,6 +105,6 @@ describe('submodule', () => {
104105
const tree = await runner.runSchematicAsync('submodule', options, appTree).toPromise();
105106
expect(
106107
JSON.parse(tree.readContent('/projects/some-lib/src/lib/path/to/customer/package.json'))
107-
).to.eql(expectedContent);
108+
).toEqual(expectedContent);
108109
});
109110
});

tsconfig.json

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
22
"compilerOptions": {
33
"baseUrl": "tsconfig",
4-
"lib": [
5-
"es2018",
6-
"dom"
7-
],
4+
"lib": ["es2018", "dom"],
85
"declaration": true,
96
"module": "commonjs",
107
"moduleResolution": "node",
@@ -20,16 +17,8 @@
2017
"sourceMap": true,
2118
"strictNullChecks": false,
2219
"target": "es6",
23-
"types": [
24-
"mocha",
25-
"node",
26-
"chai"
27-
]
20+
"types": ["jest", "node"]
2821
},
29-
"include": [
30-
"src/**/*"
31-
],
32-
"exclude": [
33-
"src/*/files/**/*"
34-
]
22+
"include": ["src/**/*"],
23+
"exclude": ["src/*/files/**/*"]
3524
}

0 commit comments

Comments
 (0)