Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
"@types/fs-extra": "4.0.2",
"@types/hammerjs": "2.0.35",
"@types/inquirer": "^0.0.44",
"@types/jasmine": "^2.8.8",
"@types/jasminewd2": "^2.0.6",
"@types/jasmine": "3.5.10",
"@types/jasminewd2": "^2.0.8",
"@types/minimist": "^1.2.0",
"@types/node": "^12.11.1",
"@types/selenium-webdriver": "3.0.7",
Expand Down Expand Up @@ -105,8 +105,8 @@
"hammerjs": "2.0.8",
"http-server": "^0.11.1",
"incremental-dom": "0.4.1",
"jasmine": "^3.1.0",
"jasmine-core": "^3.1.0",
"jasmine": "^3.5.0",
"jasmine-core": "^3.5.0",
"jquery": "3.0.0",
"karma": "~4.1.0",
"karma-chrome-launcher": "^2.2.0",
Expand Down
14 changes: 7 additions & 7 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 All @@ -141,7 +141,7 @@ const XSSI_PREFIX = ')]}\'\n';
it('emits real errors via the error path', done => {
backend.handle(TEST_POST).subscribe(undefined, (err: HttpErrorResponse) => {
expect(err instanceof HttpErrorResponse).toBe(true);
expect(err.error instanceof Error);
expect(err.error instanceof Error).toBeTrue();
expect(err.url).toBe('/test');
done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ runInEachFileSystem(() => {
});
// The "test" compilation result is just the name of the decorator being compiled
// (suffixed with `(compiled)`)
handler.compile.and.callFake((decl: ts.Declaration, analysis: any) => {
(handler.compile as any).and.callFake((decl: ts.Declaration, analysis: any) => {
logs.push(`compile: ${(decl as any).name.text}@${analysis.decoratorName} (resolved: ${
analysis.resolved})`);
return `@${analysis.decoratorName} (compiled)`;
Expand Down Expand Up @@ -183,7 +183,7 @@ runInEachFileSystem(() => {
it('should call detect on the decorator handlers with each class from the parsed file',
() => {
expect(testHandler.detect).toHaveBeenCalledTimes(5);
expect(testHandler.detect.calls.allArgs().map(args => args[1])).toEqual([
expect(testHandler.detect.calls.allArgs().map((args: any[]) => args[1])).toEqual([
null,
jasmine.arrayContaining([jasmine.objectContaining({name: 'Component'})]),
jasmine.arrayContaining([jasmine.objectContaining({name: 'Directive'})]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ describe('ClusterExecutor', () => {

beforeEach(() => {
masterRunSpy = spyOn(ClusterMaster.prototype, 'run')
.and.returnValue(Promise.resolve('CusterMaster#run()'));
.and.returnValue(Promise.resolve('CusterMaster#run()' as any));
workerRunSpy = spyOn(ClusterWorker.prototype, 'run')
.and.returnValue(Promise.resolve('CusterWorker#run()'));
.and.returnValue(Promise.resolve('CusterWorker#run()' as any));
createTaskCompletedCallback = jasmine.createSpy('createTaskCompletedCallback');

mockLogger = new MockLogger();
Expand Down
5 changes: 3 additions & 2 deletions 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'}]);
spyOn(os, 'cpus').and.returnValue([{model: 'Mock CPU'} as any]);
});

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

// Copies over files (unchanged) that did not need compiling
expect(fs.exists(_(`/node_modules/@angular/common/__ivy_ngcc__/esm5/src/version.js`)));
expect(fs.exists(_(`/node_modules/@angular/common/__ivy_ngcc__/esm5/src/version.js`)))
.toBeTrue();
expect(fs.readFile(_(`/node_modules/@angular/common/__ivy_ngcc__/esm5/src/version.js`)))
.toEqual(fs.readFile(_(`/node_modules/@angular/common/esm5/src/version.js`)));

Expand Down
11 changes: 10 additions & 1 deletion packages/compiler-cli/ngcc/test/locking/async_locker_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ runInEachFileSystem(() => {
});
spyOn(lockFile, 'read').and.callFake(() => {
log.push('read() => ' + lockFileContents);
if (lockFileContents === null) {
throw {code: 'ENOENT'};
}
return lockFileContents;
});

Expand Down Expand Up @@ -99,6 +102,9 @@ runInEachFileSystem(() => {
});
spyOn(lockFile, 'read').and.callFake(() => {
log.push('read() => ' + lockFileContents);
if (lockFileContents === null) {
throw {code: 'ENOENT'};
}
return lockFileContents;
});

Expand Down Expand Up @@ -148,6 +154,9 @@ runInEachFileSystem(() => {
});
spyOn(lockFile, 'read').and.callFake(() => {
log.push('read() => ' + lockFileContents);
if (lockFileContents === null) {
throw {code: 'ENOENT'};
}
return lockFileContents;
});

Expand All @@ -167,4 +176,4 @@ runInEachFileSystem(() => {
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ describe('unlocker', () => {
it('should attach a handler to the `disconnect` event', () => {
spyOn(process, 'on');
require('../../../src/locking/lock_file_with_child_process/unlocker');
expect(process.on).toHaveBeenCalledWith('disconnect', jasmine.any(Function));
// TODO: @JiaLiPassion, need to wait for @types/jasmine to handle the override case
Comment thread
gkalpak marked this conversation as resolved.
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42455
expect(process.on).toHaveBeenCalledWith('disconnect' as any, jasmine.any(Function));
});
});
14 changes: 9 additions & 5 deletions packages/compiler-cli/ngcc/test/packages/entry_point_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ runInEachFileSystem(() => {
const config = new NgccConfiguration(fs, _('/project'));
spyOn(config, 'getConfig').and.returnValue({
entryPoints: {[_('/project/node_modules/some_package/valid_entry_point')]: {ignore: true}}
});
} as any);
const entryPoint = getEntryPointInfo(
fs, config, new MockLogger(), SOME_PACKAGE,
_('/project/node_modules/some_package/valid_entry_point'));
Expand All @@ -95,7 +95,8 @@ runInEachFileSystem(() => {
esm2015: './some_other.js',
};
spyOn(config, 'getConfig').and.returnValue({
entryPoints: {[_('/project/node_modules/some_package/valid_entry_point')]: {override}}
entryPoints: {[_('/project/node_modules/some_package/valid_entry_point')]: {override}},
versionRange: '*'
});
const entryPoint = getEntryPointInfo(
fs, config, new MockLogger(), SOME_PACKAGE,
Expand Down Expand Up @@ -145,7 +146,9 @@ runInEachFileSystem(() => {
const override =
JSON.parse(createPackageJson('missing_package_json', {excludes: ['name']}));
spyOn(config, 'getConfig').and.returnValue({
entryPoints: {[_('/project/node_modules/some_package/missing_package_json')]: {override}}
entryPoints:
{[_('/project/node_modules/some_package/missing_package_json')]: {override}},
versionRange: '*'
});
const entryPoint = getEntryPointInfo(
fs, config, new MockLogger(), SOME_PACKAGE,
Expand Down Expand Up @@ -279,7 +282,8 @@ runInEachFileSystem(() => {
]);
const config = new NgccConfiguration(fs, _('/project'));
spyOn(config, 'getConfig').and.returnValue({
entryPoints: {[_('/project/node_modules/some_package/missing_metadata')]: {}}
entryPoints: {[_('/project/node_modules/some_package/missing_metadata')]: {}},
versionRange: '*'
});
const entryPoint = getEntryPointInfo(
fs, config, new MockLogger(), SOME_PACKAGE,
Expand Down Expand Up @@ -398,7 +402,7 @@ runInEachFileSystem(() => {
if (result === NO_ENTRY_POINT || result === INCOMPATIBLE_ENTRY_POINT) {
return fail(`Expected an entry point but got ${result}`);
}
entryPoint = result;
entryPoint = result as any;
});

it('should return `esm2015` format for `fesm2015` property', () => {
Expand Down
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});
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});
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});
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 @@ -65,10 +65,12 @@ describe('NodeJSFileSystem', () => {

describe('readdir()', () => {
it('should delegate to fs.readdirSync()', () => {
const spy = spyOn(realFs, 'readdirSync').and.returnValue(['x', 'y/z']);
const spy = spyOn(realFs, 'readdirSync').and.returnValue(['x', 'y/z'] as any);
const result = fs.readdir(abcPath);
expect(result).toEqual([relativeFrom('x'), relativeFrom('y/z')]);
expect(spy).toHaveBeenCalledWith(abcPath);
// TODO: @JiaLiPassion need to wait for @types/jasmine update to handle optional parameters.
Comment thread
gkalpak marked this conversation as resolved.
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
expect(spy as any).toHaveBeenCalledWith(abcPath);
});
});

Expand All @@ -88,7 +90,9 @@ describe('NodeJSFileSystem', () => {
const spy = spyOn(realFs, 'statSync').and.returnValue(stats);
const result = fs.stat(abcPath);
expect(result).toBe(stats);
expect(spy).toHaveBeenCalledWith(abcPath);
// TODO: @JiaLiPassion need to wait for @types/jasmine update to handle optional parameters.
Comment thread
gkalpak marked this conversation as resolved.
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
expect(spy as any).toHaveBeenCalledWith(abcPath);
});
});

Expand Down Expand Up @@ -125,7 +129,7 @@ describe('NodeJSFileSystem', () => {
const xyPath = absoluteFrom('/x/y');
const mkdirCalls: string[] = [];
const existsCalls: string[] = [];
spyOn(realFs, 'mkdirSync').and.callFake((path: string) => mkdirCalls.push(path));
spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => mkdirCalls.push(path)) as any);
spyOn(fs, 'exists').and.callFake((path: AbsoluteFsPath) => {
existsCalls.push(path);
switch (path) {
Expand Down Expand Up @@ -171,12 +175,14 @@ describe('NodeJSFileSystem', () => {
}
return false;
});
spyOn(fs, 'stat').and.returnValue({isDirectory: () => true});
const mkdirSyncSpy = spyOn(realFs, 'mkdirSync').and.callFake((path: string) => {
if (path === abcPath) {
throw new Error('It exists already. Supposedly.');
}
});
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 @@ -186,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).');
}
});
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 @@ -210,12 +217,12 @@ describe('NodeJSFileSystem', () => {
}
return false;
});
spyOn(fs, 'stat').and.returnValue({isDirectory: isDirectorySpy});
spyOn(realFs, 'mkdirSync').and.callFake((path: string) => {
if (path === abcPath) {
throw new Error('It exists already. Supposedly.');
}
});
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);

expect(() => fs.ensureDir(abcPath)).toThrowError('It exists already. Supposedly.');
expect(isDirectorySpy).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,18 +775,22 @@ runInEachFileSystem(() => {

describe('(visited file tracking)', () => {
it('should track each time a source file is visited', () => {
const addDependency = jasmine.createSpy('DependencyTracker');
const addDependency =
jasmine.createSpy<DependencyTracker['addDependency']>('DependencyTracker');
const {expression, checker} = makeExpression(
`class A { static foo = 42; } function bar() { return A.foo; }`, 'bar()');
const evaluator = makeEvaluator(checker, {...fakeDepTracker, addDependency});
evaluator.evaluate(expression);
expect(addDependency).toHaveBeenCalledTimes(2); // two declaration visited
expect(addDependency.calls.allArgs().map(args => [args[0].fileName, args[1].fileName]))
expect(
addDependency.calls.allArgs().map(
(args: Parameters<typeof addDependency>) => [args[0].fileName, args[1].fileName]))
.toEqual([[_('/entry.ts'), _('/entry.ts')], [_('/entry.ts'), _('/entry.ts')]]);
});

it('should track imported source files', () => {
const addDependency = jasmine.createSpy('DependencyTracker');
const addDependency =
jasmine.createSpy<DependencyTracker['addDependency']>('DependencyTracker');
const {expression, checker} =
makeExpression(`import {Y} from './other'; const A = Y;`, 'A', [
{name: _('/other.ts'), contents: `export const Y = 'test';`},
Expand All @@ -795,15 +799,18 @@ runInEachFileSystem(() => {
const evaluator = makeEvaluator(checker, {...fakeDepTracker, addDependency});
evaluator.evaluate(expression);
expect(addDependency).toHaveBeenCalledTimes(2);
expect(addDependency.calls.allArgs().map(args => [args[0].fileName, args[1].fileName]))
expect(
addDependency.calls.allArgs().map(
(args: Parameters<typeof addDependency>) => [args[0].fileName, args[1].fileName]))
.toEqual([
[_('/entry.ts'), _('/entry.ts')],
[_('/entry.ts'), _('/other.ts')],
]);
});

it('should track files passed through during re-exports', () => {
const addDependency = jasmine.createSpy('DependencyTracker');
const addDependency =
jasmine.createSpy<DependencyTracker['addDependency']>('DependencyTracker');
const {expression, checker} =
makeExpression(`import * as mod from './direct-reexport';`, 'mod.value.property', [
{name: _('/const.ts'), contents: 'export const value = {property: "test"};'},
Expand All @@ -823,7 +830,9 @@ runInEachFileSystem(() => {
const evaluator = makeEvaluator(checker, {...fakeDepTracker, addDependency});
evaluator.evaluate(expression);
expect(addDependency).toHaveBeenCalledTimes(2);
expect(addDependency.calls.allArgs().map(args => [args[0].fileName, args[1].fileName]))
expect(
addDependency.calls.allArgs().map(
(args: Parameters<typeof addDependency>) => [args[0].fileName, args[1].fileName]))
.toEqual([
[_('/entry.ts'), _('/direct-reexport.ts')],
// Not '/indirect-reexport.ts' or '/def.ts'.
Expand Down
Loading