Skip to content
This repository was archived by the owner on Jan 19, 2023. It is now read-only.

Commit ef4736d

Browse files
JiaLiPassionkara
authored andcommitted
build: update jasmine to 3.5 (angular#34625)
1. update jasmine to 3.5 2. update @types/jasmine to 3.5 3. update @types/jasminewd2 to 2.0.8 Also fix several cases, the new jasmine 3 will help to create test cases correctly, such as in the `jasmine 2.x` version, the following case will pass ``` expect(1 == 2); ``` But in jsamine 3, the case will need to be ``` expect(1 == 2).toBeTrue(); ``` PR Close angular#34625
1 parent db4a448 commit ef4736d

File tree

29 files changed

+124
-85
lines changed

29 files changed

+124
-85
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
"@types/fs-extra": "4.0.2",
7373
"@types/hammerjs": "2.0.35",
7474
"@types/inquirer": "^0.0.44",
75-
"@types/jasmine": "^2.8.8",
76-
"@types/jasminewd2": "^2.0.6",
75+
"@types/jasmine": "3.5.10",
76+
"@types/jasminewd2": "^2.0.8",
7777
"@types/minimist": "^1.2.0",
7878
"@types/node": "^12.11.1",
7979
"@types/selenium-webdriver": "3.0.7",
@@ -105,8 +105,8 @@
105105
"hammerjs": "2.0.8",
106106
"http-server": "^0.11.1",
107107
"incremental-dom": "0.4.1",
108-
"jasmine": "^3.1.0",
109-
"jasmine-core": "^3.1.0",
108+
"jasmine": "^3.5.0",
109+
"jasmine-core": "^3.5.0",
110110
"jquery": "3.0.0",
111111
"karma": "~4.1.0",
112112
"karma-chrome-launcher": "^2.2.0",

packages/common/http/test/xhr_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const XSSI_PREFIX = ')]}\'\n';
141141
it('emits real errors via the error path', done => {
142142
backend.handle(TEST_POST).subscribe(undefined, (err: HttpErrorResponse) => {
143143
expect(err instanceof HttpErrorResponse).toBe(true);
144-
expect(err.error instanceof Error);
144+
expect(err.error instanceof Error).toBeTrue();
145145
expect(err.url).toBe('/test');
146146
done();
147147
});

packages/compiler-cli/ngcc/test/analysis/decoration_analyzer_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ runInEachFileSystem(() => {
9595
});
9696
// The "test" compilation result is just the name of the decorator being compiled
9797
// (suffixed with `(compiled)`)
98-
handler.compile.and.callFake((decl: ts.Declaration, analysis: any) => {
98+
(handler.compile as any).and.callFake((decl: ts.Declaration, analysis: any) => {
9999
logs.push(`compile: ${(decl as any).name.text}@${analysis.decoratorName} (resolved: ${
100100
analysis.resolved})`);
101101
return `@${analysis.decoratorName} (compiled)`;
@@ -183,7 +183,7 @@ runInEachFileSystem(() => {
183183
it('should call detect on the decorator handlers with each class from the parsed file',
184184
() => {
185185
expect(testHandler.detect).toHaveBeenCalledTimes(5);
186-
expect(testHandler.detect.calls.allArgs().map(args => args[1])).toEqual([
186+
expect(testHandler.detect.calls.allArgs().map((args: any[]) => args[1])).toEqual([
187187
null,
188188
jasmine.arrayContaining([jasmine.objectContaining({name: 'Component'})]),
189189
jasmine.arrayContaining([jasmine.objectContaining({name: 'Directive'})]),

packages/compiler-cli/ngcc/test/execution/cluster/executor_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ describe('ClusterExecutor', () => {
3434

3535
beforeEach(() => {
3636
masterRunSpy = spyOn(ClusterMaster.prototype, 'run')
37-
.and.returnValue(Promise.resolve('CusterMaster#run()'));
37+
.and.returnValue(Promise.resolve('CusterMaster#run()' as any));
3838
workerRunSpy = spyOn(ClusterWorker.prototype, 'run')
39-
.and.returnValue(Promise.resolve('CusterWorker#run()'));
39+
.and.returnValue(Promise.resolve('CusterWorker#run()' as any));
4040
createTaskCompletedCallback = jasmine.createSpy('createTaskCompletedCallback');
4141

4242
mockLogger = new MockLogger();

packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ runInEachFileSystem(() => {
3838
initMockFileSystem(fs, testFiles);
3939

4040
// Force single-process execution in unit tests by mocking available CPUs to 1.
41-
spyOn(os, 'cpus').and.returnValue([{model: 'Mock CPU'}]);
41+
spyOn(os, 'cpus').and.returnValue([{ model: 'Mock CPU' } as any]);
4242
});
4343

4444
it('should run ngcc without errors for esm2015', () => {
@@ -962,7 +962,8 @@ runInEachFileSystem(() => {
962962
.toMatch(ANGULAR_CORE_IMPORT_REGEX);
963963

964964
// Copies over files (unchanged) that did not need compiling
965-
expect(fs.exists(_(`/node_modules/@angular/common/__ivy_ngcc__/esm5/src/version.js`)));
965+
expect(fs.exists(_(`/node_modules/@angular/common/__ivy_ngcc__/esm5/src/version.js`)))
966+
.toBeTrue();
966967
expect(fs.readFile(_(`/node_modules/@angular/common/__ivy_ngcc__/esm5/src/version.js`)))
967968
.toEqual(fs.readFile(_(`/node_modules/@angular/common/esm5/src/version.js`)));
968969

packages/compiler-cli/ngcc/test/locking/async_locker_spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ runInEachFileSystem(() => {
6666
});
6767
spyOn(lockFile, 'read').and.callFake(() => {
6868
log.push('read() => ' + lockFileContents);
69+
if (lockFileContents === null) {
70+
throw {code: 'ENOENT'};
71+
}
6972
return lockFileContents;
7073
});
7174

@@ -99,6 +102,9 @@ runInEachFileSystem(() => {
99102
});
100103
spyOn(lockFile, 'read').and.callFake(() => {
101104
log.push('read() => ' + lockFileContents);
105+
if (lockFileContents === null) {
106+
throw {code: 'ENOENT'};
107+
}
102108
return lockFileContents;
103109
});
104110

@@ -148,6 +154,9 @@ runInEachFileSystem(() => {
148154
});
149155
spyOn(lockFile, 'read').and.callFake(() => {
150156
log.push('read() => ' + lockFileContents);
157+
if (lockFileContents === null) {
158+
throw {code: 'ENOENT'};
159+
}
151160
return lockFileContents;
152161
});
153162

@@ -167,4 +176,4 @@ runInEachFileSystem(() => {
167176
});
168177
});
169178
});
170-
});
179+
});

packages/compiler-cli/ngcc/test/locking/lockfile_with_child_process/unlocker_spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('unlocker', () => {
1212
it('should attach a handler to the `disconnect` event', () => {
1313
spyOn(process, 'on');
1414
require('../../../src/locking/lock_file_with_child_process/unlocker');
15-
expect(process.on).toHaveBeenCalledWith('disconnect', jasmine.any(Function));
15+
// TODO: @JiaLiPassion, need to wait for @types/jasmine to handle the override case
16+
expect(process.on).toHaveBeenCalledWith('disconnect' as any, jasmine.any(Function));
1617
});
1718
});

packages/compiler-cli/ngcc/test/packages/entry_point_spec.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ runInEachFileSystem(() => {
7070
const config = new NgccConfiguration(fs, _('/project'));
7171
spyOn(config, 'getConfig').and.returnValue({
7272
entryPoints: {[_('/project/node_modules/some_package/valid_entry_point')]: {ignore: true}}
73-
});
73+
} as any);
7474
const entryPoint = getEntryPointInfo(
7575
fs, config, new MockLogger(), SOME_PACKAGE,
7676
_('/project/node_modules/some_package/valid_entry_point'));
@@ -95,7 +95,8 @@ runInEachFileSystem(() => {
9595
esm2015: './some_other.js',
9696
};
9797
spyOn(config, 'getConfig').and.returnValue({
98-
entryPoints: {[_('/project/node_modules/some_package/valid_entry_point')]: {override}}
98+
entryPoints: {[_('/project/node_modules/some_package/valid_entry_point')]: {override}},
99+
versionRange: '*'
99100
});
100101
const entryPoint = getEntryPointInfo(
101102
fs, config, new MockLogger(), SOME_PACKAGE,
@@ -145,7 +146,9 @@ runInEachFileSystem(() => {
145146
const override =
146147
JSON.parse(createPackageJson('missing_package_json', {excludes: ['name']}));
147148
spyOn(config, 'getConfig').and.returnValue({
148-
entryPoints: {[_('/project/node_modules/some_package/missing_package_json')]: {override}}
149+
entryPoints:
150+
{[_('/project/node_modules/some_package/missing_package_json')]: {override}},
151+
versionRange: '*'
149152
});
150153
const entryPoint = getEntryPointInfo(
151154
fs, config, new MockLogger(), SOME_PACKAGE,
@@ -279,7 +282,8 @@ runInEachFileSystem(() => {
279282
]);
280283
const config = new NgccConfiguration(fs, _('/project'));
281284
spyOn(config, 'getConfig').and.returnValue({
282-
entryPoints: {[_('/project/node_modules/some_package/missing_metadata')]: {}}
285+
entryPoints: {[_('/project/node_modules/some_package/missing_metadata')]: {}},
286+
versionRange: '*'
283287
});
284288
const entryPoint = getEntryPointInfo(
285289
fs, config, new MockLogger(), SOME_PACKAGE,
@@ -398,7 +402,7 @@ runInEachFileSystem(() => {
398402
if (result === NO_ENTRY_POINT || result === INCOMPATIBLE_ENTRY_POINT) {
399403
return fail(`Expected an entry point but got ${result}`);
400404
}
401-
entryPoint = result;
405+
entryPoint = result as any;
402406
});
403407

404408
it('should return `esm2015` format for `fesm2015` property', () => {

packages/compiler-cli/src/ngtsc/file_system/test/cached_file_system_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('CachedFileSystem', () => {
4747
let lstatSpy: jasmine.Spy;
4848
beforeEach(() => {
4949
// For most of the tests the files are not symbolic links.
50-
lstatSpy = spyOn(delegate, 'lstat').and.returnValue({isSymbolicLink: () => false});
50+
lstatSpy = spyOn(delegate, 'lstat').and.returnValue({ isSymbolicLink: () => false } as any);
5151
});
5252

5353
it('should call delegate if not in cache', () => {
@@ -93,7 +93,7 @@ describe('CachedFileSystem', () => {
9393
describe('invalidateCaches()', () => {
9494
it('should call the delegate `readFile()` if the path for the cached file has been invalidated',
9595
() => {
96-
spyOn(delegate, 'lstat').and.returnValue({isSymbolicLink: () => false});
96+
spyOn(delegate, 'lstat').and.returnValue({ isSymbolicLink: () => false } as any);
9797
const spy = spyOn(delegate, 'readFile').and.returnValue('Some contents');
9898
fs.readFile(abcPath); // Call once to fill the cache
9999
spy.calls.reset();
@@ -230,7 +230,7 @@ describe('CachedFileSystem', () => {
230230
describe('moveFile()', () => {
231231
beforeEach(() => {
232232
// `moveFile()` relies upon `readFile` which calls through to `lstat()`, so stub it out.
233-
spyOn(delegate, 'lstat').and.returnValue({isSymbolicLink: () => false});
233+
spyOn(delegate, 'lstat').and.returnValue({ isSymbolicLink: () => false } as any);
234234
});
235235

236236
it('should call delegate', () => {

packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ describe('NodeJSFileSystem', () => {
6565

6666
describe('readdir()', () => {
6767
it('should delegate to fs.readdirSync()', () => {
68-
const spy = spyOn(realFs, 'readdirSync').and.returnValue(['x', 'y/z']);
68+
const spy = spyOn(realFs, 'readdirSync').and.returnValue(['x', 'y/z'] as any);
6969
const result = fs.readdir(abcPath);
7070
expect(result).toEqual([relativeFrom('x'), relativeFrom('y/z')]);
71-
expect(spy).toHaveBeenCalledWith(abcPath);
71+
// TODO: @JiaLiPassion need to wait for @types/jasmine update to handle optional parameters.
72+
expect(spy as any).toHaveBeenCalledWith(abcPath);
7273
});
7374
});
7475

@@ -88,7 +89,8 @@ describe('NodeJSFileSystem', () => {
8889
const spy = spyOn(realFs, 'statSync').and.returnValue(stats);
8990
const result = fs.stat(abcPath);
9091
expect(result).toBe(stats);
91-
expect(spy).toHaveBeenCalledWith(abcPath);
92+
// TODO: @JiaLiPassion need to wait for @types/jasmine update to handle optional parameters.
93+
expect(spy as any).toHaveBeenCalledWith(abcPath);
9294
});
9395
});
9496

@@ -125,7 +127,7 @@ describe('NodeJSFileSystem', () => {
125127
const xyPath = absoluteFrom('/x/y');
126128
const mkdirCalls: string[] = [];
127129
const existsCalls: string[] = [];
128-
spyOn(realFs, 'mkdirSync').and.callFake((path: string) => mkdirCalls.push(path));
130+
spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => mkdirCalls.push(path)) as any);
129131
spyOn(fs, 'exists').and.callFake((path: AbsoluteFsPath) => {
130132
existsCalls.push(path);
131133
switch (path) {
@@ -171,12 +173,12 @@ describe('NodeJSFileSystem', () => {
171173
}
172174
return false;
173175
});
174-
spyOn(fs, 'stat').and.returnValue({isDirectory: () => true});
175-
const mkdirSyncSpy = spyOn(realFs, 'mkdirSync').and.callFake((path: string) => {
176+
spyOn(fs, 'stat').and.returnValue({ isDirectory: () => true } as any);
177+
const mkdirSyncSpy = spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
176178
if (path === abcPath) {
177179
throw new Error('It exists already. Supposedly.');
178180
}
179-
});
181+
}) as any);
180182

181183
fs.ensureDir(abcPath);
182184
expect(mkdirSyncSpy).toHaveBeenCalledTimes(3);
@@ -186,11 +188,11 @@ describe('NodeJSFileSystem', () => {
186188

187189
it('should fail if creating the directory throws and the directory does not exist', () => {
188190
spyOn(fs, 'exists').and.returnValue(false);
189-
spyOn(realFs, 'mkdirSync').and.callFake((path: string) => {
191+
spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
190192
if (path === abcPath) {
191193
throw new Error('Unable to create directory (for whatever reason).');
192194
}
193-
});
195+
}) as any);
194196

195197
expect(() => fs.ensureDir(abcPath))
196198
.toThrowError('Unable to create directory (for whatever reason).');
@@ -210,12 +212,12 @@ describe('NodeJSFileSystem', () => {
210212
}
211213
return false;
212214
});
213-
spyOn(fs, 'stat').and.returnValue({isDirectory: isDirectorySpy});
214-
spyOn(realFs, 'mkdirSync').and.callFake((path: string) => {
215+
spyOn(fs, 'stat').and.returnValue({ isDirectory: isDirectorySpy } as any);
216+
spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
215217
if (path === abcPath) {
216218
throw new Error('It exists already. Supposedly.');
217219
}
218-
});
220+
}) as any);
219221

220222
expect(() => fs.ensureDir(abcPath)).toThrowError('It exists already. Supposedly.');
221223
expect(isDirectorySpy).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)