diff --git a/packages/compiler-cli/src/ngtsc/partial_evaluator/test/evaluator_spec.ts b/packages/compiler-cli/src/ngtsc/partial_evaluator/test/evaluator_spec.ts index 19b814efb5..bf62189794 100644 --- a/packages/compiler-cli/src/ngtsc/partial_evaluator/test/evaluator_spec.ts +++ b/packages/compiler-cli/src/ngtsc/partial_evaluator/test/evaluator_spec.ts @@ -790,25 +790,28 @@ runInEachFileSystem(() => { it('should track each time a source file is visited', () => { const addDependency = jasmine.createSpy('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) => [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'); - 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) => [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'); - 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) => [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], ]); }); });