test(compiler-cli): ensure partial-evaluator tests are not brittle to case-sensitivity (#36859)
These tests were matching file-paths against what is retrieved from the TS compiler. But the TS compiler paths have been canonicalised, so the tests were brittle on case-insensitive file-systems. PR Close #36859
This commit is contained in:
parent
8ce38cac0d
commit
9e43e4900e
|
@ -790,25 +790,28 @@ runInEachFileSystem(() => {
|
|||
it('should track each time a source file is visited', () => {
|
||||
const addDependency =
|
||||
jasmine.createSpy<DependencyTracker['addDependency']>('DependencyTracker');
|
||||
const {expression, checker} = makeExpression(
|
||||
const {expression, checker, program} = makeExpression(
|
||||
`class A { static foo = 42; } function bar() { return A.foo; }`, 'bar()');
|
||||
const entryPath = getSourceFileOrError(program, _('/entry.ts')).fileName;
|
||||
const evaluator = makeEvaluator(checker, {...fakeDepTracker, addDependency});
|
||||
evaluator.evaluate(expression);
|
||||
expect(addDependency).toHaveBeenCalledTimes(2); // two declaration visited
|
||||
expect(
|
||||
addDependency.calls.allArgs().map(
|
||||
(args: Parameters<typeof addDependency>) => [args[0].fileName, args[1].fileName]))
|
||||
.toEqual([[_('/entry.ts'), _('/entry.ts')], [_('/entry.ts'), _('/entry.ts')]]);
|
||||
.toEqual([[entryPath, entryPath], [entryPath, entryPath]]);
|
||||
});
|
||||
|
||||
it('should track imported source files', () => {
|
||||
const addDependency =
|
||||
jasmine.createSpy<DependencyTracker['addDependency']>('DependencyTracker');
|
||||
const {expression, checker} =
|
||||
const {expression, checker, program} =
|
||||
makeExpression(`import {Y} from './other'; const A = Y;`, 'A', [
|
||||
{name: _('/other.ts'), contents: `export const Y = 'test';`},
|
||||
{name: _('/not-visited.ts'), contents: `export const Z = 'nope';`}
|
||||
]);
|
||||
const entryPath = getSourceFileOrError(program, _('/entry.ts')).fileName;
|
||||
const otherPath = getSourceFileOrError(program, _('/other.ts')).fileName;
|
||||
const evaluator = makeEvaluator(checker, {...fakeDepTracker, addDependency});
|
||||
evaluator.evaluate(expression);
|
||||
expect(addDependency).toHaveBeenCalledTimes(2);
|
||||
|
@ -816,15 +819,15 @@ runInEachFileSystem(() => {
|
|||
addDependency.calls.allArgs().map(
|
||||
(args: Parameters<typeof addDependency>) => [args[0].fileName, args[1].fileName]))
|
||||
.toEqual([
|
||||
[_('/entry.ts'), _('/entry.ts')],
|
||||
[_('/entry.ts'), _('/other.ts')],
|
||||
[entryPath, entryPath],
|
||||
[entryPath, otherPath],
|
||||
]);
|
||||
});
|
||||
|
||||
it('should track files passed through during re-exports', () => {
|
||||
const addDependency =
|
||||
jasmine.createSpy<DependencyTracker['addDependency']>('DependencyTracker');
|
||||
const {expression, checker} =
|
||||
const {expression, checker, program} =
|
||||
makeExpression(`import * as mod from './direct-reexport';`, 'mod.value.property', [
|
||||
{name: _('/const.ts'), contents: 'export const value = {property: "test"};'},
|
||||
{
|
||||
|
@ -841,16 +844,19 @@ runInEachFileSystem(() => {
|
|||
},
|
||||
]);
|
||||
const evaluator = makeEvaluator(checker, {...fakeDepTracker, addDependency});
|
||||
const entryPath = getSourceFileOrError(program, _('/entry.ts')).fileName;
|
||||
const directReexportPath = getSourceFileOrError(program, _('/direct-reexport.ts')).fileName;
|
||||
const constPath = getSourceFileOrError(program, _('/const.ts')).fileName;
|
||||
evaluator.evaluate(expression);
|
||||
expect(addDependency).toHaveBeenCalledTimes(2);
|
||||
expect(
|
||||
addDependency.calls.allArgs().map(
|
||||
(args: Parameters<typeof addDependency>) => [args[0].fileName, args[1].fileName]))
|
||||
.toEqual([
|
||||
[_('/entry.ts'), _('/direct-reexport.ts')],
|
||||
[entryPath, directReexportPath],
|
||||
// Not '/indirect-reexport.ts' or '/def.ts'.
|
||||
// TS skips through them when finding the original symbol for `value`
|
||||
[_('/entry.ts'), _('/const.ts')],
|
||||
[entryPath, constPath],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue