fix(zone.js): add issue numbers of @types/jasmine
to the test cases (#34625)
Some cases will still need to use `spy as any` cast, because `@types/jasmine` have some issues, 1. The issue jasmine doesn't handle optional method properties, https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486 2. The issue jasmine doesn't handle overload method correctly, https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42455 PR Close #34625
This commit is contained in:

committed by
Kara Erickson

parent
b28a5f6eef
commit
421b6a97d6
@ -38,7 +38,7 @@ runInEachFileSystem(() => {
|
||||
initMockFileSystem(fs, testFiles);
|
||||
|
||||
// Force single-process execution in unit tests by mocking available CPUs to 1.
|
||||
spyOn(os, 'cpus').and.returnValue([{ model: 'Mock CPU' } as any]);
|
||||
spyOn(os, 'cpus').and.returnValue([{model: 'Mock CPU'} as any]);
|
||||
});
|
||||
|
||||
it('should run ngcc without errors for esm2015', () => {
|
||||
|
@ -13,6 +13,7 @@ describe('unlocker', () => {
|
||||
spyOn(process, 'on');
|
||||
require('../../../src/locking/lock_file_with_child_process/unlocker');
|
||||
// TODO: @JiaLiPassion, need to wait for @types/jasmine to handle the override case
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42455
|
||||
expect(process.on).toHaveBeenCalledWith('disconnect' as any, jasmine.any(Function));
|
||||
});
|
||||
});
|
||||
|
@ -47,7 +47,7 @@ describe('CachedFileSystem', () => {
|
||||
let lstatSpy: jasmine.Spy;
|
||||
beforeEach(() => {
|
||||
// For most of the tests the files are not symbolic links.
|
||||
lstatSpy = spyOn(delegate, 'lstat').and.returnValue({ isSymbolicLink: () => false } as any);
|
||||
lstatSpy = spyOn(delegate, 'lstat').and.returnValue({isSymbolicLink: () => false} as any);
|
||||
});
|
||||
|
||||
it('should call delegate if not in cache', () => {
|
||||
@ -93,7 +93,7 @@ describe('CachedFileSystem', () => {
|
||||
describe('invalidateCaches()', () => {
|
||||
it('should call the delegate `readFile()` if the path for the cached file has been invalidated',
|
||||
() => {
|
||||
spyOn(delegate, 'lstat').and.returnValue({ isSymbolicLink: () => false } as any);
|
||||
spyOn(delegate, 'lstat').and.returnValue({isSymbolicLink: () => false} as any);
|
||||
const spy = spyOn(delegate, 'readFile').and.returnValue('Some contents');
|
||||
fs.readFile(abcPath); // Call once to fill the cache
|
||||
spy.calls.reset();
|
||||
@ -230,7 +230,7 @@ describe('CachedFileSystem', () => {
|
||||
describe('moveFile()', () => {
|
||||
beforeEach(() => {
|
||||
// `moveFile()` relies upon `readFile` which calls through to `lstat()`, so stub it out.
|
||||
spyOn(delegate, 'lstat').and.returnValue({ isSymbolicLink: () => false } as any);
|
||||
spyOn(delegate, 'lstat').and.returnValue({isSymbolicLink: () => false} as any);
|
||||
});
|
||||
|
||||
it('should call delegate', () => {
|
||||
|
@ -69,6 +69,7 @@ describe('NodeJSFileSystem', () => {
|
||||
const result = fs.readdir(abcPath);
|
||||
expect(result).toEqual([relativeFrom('x'), relativeFrom('y/z')]);
|
||||
// TODO: @JiaLiPassion need to wait for @types/jasmine update to handle optional parameters.
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
|
||||
expect(spy as any).toHaveBeenCalledWith(abcPath);
|
||||
});
|
||||
});
|
||||
@ -90,6 +91,7 @@ describe('NodeJSFileSystem', () => {
|
||||
const result = fs.stat(abcPath);
|
||||
expect(result).toBe(stats);
|
||||
// TODO: @JiaLiPassion need to wait for @types/jasmine update to handle optional parameters.
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
|
||||
expect(spy as any).toHaveBeenCalledWith(abcPath);
|
||||
});
|
||||
});
|
||||
@ -173,12 +175,14 @@ describe('NodeJSFileSystem', () => {
|
||||
}
|
||||
return false;
|
||||
});
|
||||
spyOn(fs, 'stat').and.returnValue({ isDirectory: () => true } as any);
|
||||
const mkdirSyncSpy = spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
|
||||
if (path === abcPath) {
|
||||
throw new Error('It exists already. Supposedly.');
|
||||
}
|
||||
}) as any);
|
||||
spyOn(fs, 'stat').and.returnValue({isDirectory: () => true} as any);
|
||||
const mkdirSyncSpy =
|
||||
spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
|
||||
if (path === abcPath) {
|
||||
throw new Error(
|
||||
'It exists already. Supposedly.');
|
||||
}
|
||||
}) as any);
|
||||
|
||||
fs.ensureDir(abcPath);
|
||||
expect(mkdirSyncSpy).toHaveBeenCalledTimes(3);
|
||||
@ -188,11 +192,12 @@ describe('NodeJSFileSystem', () => {
|
||||
|
||||
it('should fail if creating the directory throws and the directory does not exist', () => {
|
||||
spyOn(fs, 'exists').and.returnValue(false);
|
||||
spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
|
||||
if (path === abcPath) {
|
||||
throw new Error('Unable to create directory (for whatever reason).');
|
||||
}
|
||||
}) as any);
|
||||
spyOn(realFs, 'mkdirSync')
|
||||
.and.callFake(((path: string) => {
|
||||
if (path === abcPath) {
|
||||
throw new Error('Unable to create directory (for whatever reason).');
|
||||
}
|
||||
}) as any);
|
||||
|
||||
expect(() => fs.ensureDir(abcPath))
|
||||
.toThrowError('Unable to create directory (for whatever reason).');
|
||||
@ -212,12 +217,12 @@ describe('NodeJSFileSystem', () => {
|
||||
}
|
||||
return false;
|
||||
});
|
||||
spyOn(fs, 'stat').and.returnValue({ isDirectory: isDirectorySpy } as any);
|
||||
spyOn(fs, 'stat').and.returnValue({isDirectory: isDirectorySpy} as any);
|
||||
spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
|
||||
if (path === abcPath) {
|
||||
throw new Error('It exists already. Supposedly.');
|
||||
}
|
||||
}) as any);
|
||||
if (path === abcPath) {
|
||||
throw new Error('It exists already. Supposedly.');
|
||||
}
|
||||
}) as any);
|
||||
|
||||
expect(() => fs.ensureDir(abcPath)).toThrowError('It exists already. Supposedly.');
|
||||
expect(isDirectorySpy).toHaveBeenCalledTimes(1);
|
||||
|
@ -41,7 +41,9 @@ describe('ngc transformer command-line', () => {
|
||||
basePath = support.basePath;
|
||||
outDir = path.join(basePath, 'built');
|
||||
process.chdir(basePath);
|
||||
write = (fileName: string, content: string) => { support.write(fileName, content); };
|
||||
write = (fileName: string, content: string) => {
|
||||
support.write(fileName, content);
|
||||
};
|
||||
|
||||
write('tsconfig-base.json', `{
|
||||
"compilerOptions": {
|
||||
@ -96,8 +98,9 @@ describe('ngc transformer command-line', () => {
|
||||
});
|
||||
|
||||
describe('errors', () => {
|
||||
|
||||
beforeEach(() => { errorSpy.and.stub(); });
|
||||
beforeEach(() => {
|
||||
errorSpy.and.stub();
|
||||
});
|
||||
|
||||
it('should not print the stack trace if user input file does not exist', () => {
|
||||
writeConfig(`{
|
||||
@ -231,7 +234,6 @@ describe('ngc transformer command-line', () => {
|
||||
});
|
||||
|
||||
describe('compile ngfactory files', () => {
|
||||
|
||||
it('should compile ngfactory files that are not referenced by root files', () => {
|
||||
writeConfig(`{
|
||||
"extends": "./tsconfig-base.json",
|
||||
@ -1122,7 +1124,6 @@ describe('ngc transformer command-line', () => {
|
||||
});
|
||||
|
||||
describe('with external symbol re-exports enabled', () => {
|
||||
|
||||
it('should be able to compile multiple libraries with summaries', () => {
|
||||
// Note: we need to emit the generated code for the libraries
|
||||
// into the node_modules, as that is the only way that we
|
||||
@ -1560,11 +1561,13 @@ describe('ngc transformer command-line', () => {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
||||
const timerToken = 100;
|
||||
// TODO: @JiaLiPassion, need to wait @types/jasmine to handle optional method case
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
|
||||
spyOn(ts.sys as any, 'setTimeout').and.callFake((callback: () => void) => {
|
||||
timer = callback;
|
||||
return timerToken;
|
||||
});
|
||||
// TODO: @JiaLiPassion, need to wait @types/jasmine to handle optional method case
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
|
||||
spyOn(ts.sys as any, 'clearTimeout').and.callFake((token: number) => {
|
||||
if (token == timerToken) {
|
||||
timer = undefined;
|
||||
@ -1617,7 +1620,9 @@ describe('ngc transformer command-line', () => {
|
||||
`);
|
||||
});
|
||||
|
||||
afterEach(() => { jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; });
|
||||
afterEach(() => {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||
});
|
||||
|
||||
function writeAppConfig(location: string) {
|
||||
writeConfig(`{
|
||||
@ -1672,11 +1677,13 @@ describe('ngc transformer command-line', () => {
|
||||
`);
|
||||
}));
|
||||
|
||||
it('should recompile when the html file changes',
|
||||
expectRecompile(() => { write('greet.html', '<p> Hello {{name}} again!</p>'); }));
|
||||
it('should recompile when the html file changes', expectRecompile(() => {
|
||||
write('greet.html', '<p> Hello {{name}} again!</p>');
|
||||
}));
|
||||
|
||||
it('should recompile when the css file changes',
|
||||
expectRecompile(() => { write('greet.css', `p.greeting { color: blue }`); }));
|
||||
it('should recompile when the css file changes', expectRecompile(() => {
|
||||
write('greet.css', `p.greeting { color: blue }`);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('regressions', () => {
|
||||
@ -2041,8 +2048,8 @@ describe('ngc transformer command-line', () => {
|
||||
expect(exitCode).toBe(1, 'Compile was expected to fail');
|
||||
const srcPathWithSep = `lib/`;
|
||||
expect(messages[0])
|
||||
.toEqual(
|
||||
`${srcPathWithSep}test.component.ts(6,21): Error during template compile of 'TestComponent'
|
||||
.toEqual(`${
|
||||
srcPathWithSep}test.component.ts(6,21): Error during template compile of 'TestComponent'
|
||||
Tagged template expressions are not supported in metadata in 't1'
|
||||
't1' references 't2' at ${srcPathWithSep}indirect1.ts(3,27)
|
||||
't2' contains the error at ${srcPathWithSep}indirect2.ts(4,27).
|
||||
@ -2051,7 +2058,6 @@ describe('ngc transformer command-line', () => {
|
||||
});
|
||||
|
||||
describe('tree shakeable services', () => {
|
||||
|
||||
function compileService(source: string): string {
|
||||
write('service.ts', source);
|
||||
|
||||
|
Reference in New Issue
Block a user