build: update jasmine to 3.5 (#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 #34625
This commit is contained in:

committed by
Kara Erickson

parent
52ab9397a0
commit
b28a5f6eef
@ -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', () => {
|
||||
@ -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();
|
||||
@ -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', () => {
|
||||
|
@ -65,10 +65,11 @@ 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.
|
||||
expect(spy as any).toHaveBeenCalledWith(abcPath);
|
||||
});
|
||||
});
|
||||
|
||||
@ -88,7 +89,8 @@ 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.
|
||||
expect(spy as any).toHaveBeenCalledWith(abcPath);
|
||||
});
|
||||
});
|
||||
|
||||
@ -125,7 +127,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) {
|
||||
@ -171,12 +173,12 @@ describe('NodeJSFileSystem', () => {
|
||||
}
|
||||
return false;
|
||||
});
|
||||
spyOn(fs, 'stat').and.returnValue({isDirectory: () => true});
|
||||
const mkdirSyncSpy = spyOn(realFs, 'mkdirSync').and.callFake((path: string) => {
|
||||
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);
|
||||
@ -186,11 +188,11 @@ 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) => {
|
||||
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).');
|
||||
@ -210,12 +212,12 @@ describe('NodeJSFileSystem', () => {
|
||||
}
|
||||
return false;
|
||||
});
|
||||
spyOn(fs, 'stat').and.returnValue({isDirectory: isDirectorySpy});
|
||||
spyOn(realFs, 'mkdirSync').and.callFake((path: string) => {
|
||||
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);
|
||||
|
@ -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';`},
|
||||
@ -795,7 +799,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'), _('/entry.ts')],
|
||||
[_('/entry.ts'), _('/other.ts')],
|
||||
@ -803,7 +809,8 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
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"};'},
|
||||
@ -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'.
|
||||
|
Reference in New Issue
Block a user