Skip to content

Commit

Permalink
fix(zone.js): add issue numbers of @types/jasmine to the test cases (
Browse files Browse the repository at this point in the history
…angular#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, DefinitelyTyped/DefinitelyTyped#43486
2. The issue jasmine doesn't handle overload method correctly, DefinitelyTyped/DefinitelyTyped#42455

PR Close angular#34625
  • Loading branch information
JiaLiPassion authored and kara committed Apr 8, 2020
1 parent ef4736d commit 41667de
Show file tree
Hide file tree
Showing 22 changed files with 5,831 additions and 5,583 deletions.
12 changes: 6 additions & 6 deletions packages/common/http/test/xhr_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const XSSI_PREFIX = ')]}\'\n';

{
describe('XhrBackend', () => {
let factory: MockXhrFactory = null !;
let backend: HttpXhrBackend = null !;
let factory: MockXhrFactory = null!;
let backend: HttpXhrBackend = null!;
beforeEach(() => {
factory = new MockXhrFactory();
backend = new HttpXhrBackend(factory);
Expand Down Expand Up @@ -92,7 +92,7 @@ const XSSI_PREFIX = ')]}\'\n';
factory.mock.mockFlush(200, 'OK', JSON.stringify({data: 'some data'}));
expect(events.length).toBe(2);
const res = events[1] as HttpResponse<{data: string}>;
expect(res.body !.data).toBe('some data');
expect(res.body!.data).toBe('some data');
});
it('handles a blank json response', () => {
const events = trackEvents(backend.handle(TEST_POST.clone({responseType: 'json'})));
Expand All @@ -106,14 +106,14 @@ const XSSI_PREFIX = ')]}\'\n';
factory.mock.mockFlush(500, 'Error', JSON.stringify({data: 'some data'}));
expect(events.length).toBe(2);
const res = events[1] as any as HttpErrorResponse;
expect(res.error !.data).toBe('some data');
expect(res.error!.data).toBe('some data');
});
it('handles a json error response with XSSI prefix', () => {
const events = trackEvents(backend.handle(TEST_POST.clone({responseType: 'json'})));
factory.mock.mockFlush(500, 'Error', XSSI_PREFIX + JSON.stringify({data: 'some data'}));
expect(events.length).toBe(2);
const res = events[1] as any as HttpErrorResponse;
expect(res.error !.data).toBe('some data');
expect(res.error!.data).toBe('some data');
});
it('handles a json string response', () => {
const events = trackEvents(backend.handle(TEST_POST.clone({responseType: 'json'})));
Expand All @@ -128,7 +128,7 @@ const XSSI_PREFIX = ')]}\'\n';
factory.mock.mockFlush(200, 'OK', XSSI_PREFIX + JSON.stringify({data: 'some data'}));
expect(events.length).toBe(2);
const res = events[1] as HttpResponse<{data: string}>;
expect(res.body !.data).toBe('some data');
expect(res.body!.data).toBe('some data');
});
it('emits unsuccessful responses via the error path', done => {
backend.handle(TEST_POST).subscribe(undefined, (err: HttpErrorResponse) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand All @@ -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);
});
});
Expand Down Expand Up @@ -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);
Expand All @@ -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).');
Expand All @@ -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);
Expand Down
32 changes: 19 additions & 13 deletions packages/compiler-cli/test/ngc_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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(`{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(`{
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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).
Expand All @@ -2051,7 +2058,6 @@ describe('ngc transformer command-line', () => {
});

describe('tree shakeable services', () => {

function compileService(source: string): string {
write('service.ts', source);

Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/test/output/value_util_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe('convertValueToOutputAst', () => {
it('should convert all array elements, including undefined', () => {
const ctx = null;
const value = new Array(3).concat('foo');
const expr = convertValueToOutputAst(ctx !, value) as o.LiteralArrayExpr;
expect(expr instanceof o.LiteralArrayExpr);
const expr = convertValueToOutputAst(ctx!, value) as o.LiteralArrayExpr;
expect(expr instanceof o.LiteralArrayExpr).toBe(true);
expect(expr.entries.length).toBe(4);
for (let i = 0; i < 4; ++i) {
expect(expr.entries[i] instanceof o.Expression).toBe(true);
Expand Down
Loading

0 comments on commit 41667de

Please sign in to comment.