Skip to content

Commit

Permalink
simplify further the e2e clutz test
Browse files Browse the repository at this point in the history
Separate from the golden testing, tsickle has a test that just feeds
**/*.d.ts into the TypeScript compiler, to verify that the generated
d.ts are valid.

Simplify this code to just glob for those files (rather than gathering
them from each test separately), so that we can move one file in particular
out of the goldens tree.

Moving this file out unblocks an upcoming change, which is more cautious
about the handling of d.ts files and goldens.  This particular moved .d.ts
is not a golden, it's just needed for this compilation test.

PiperOrigin-RevId: 327506169
  • Loading branch information
evmar authored and copybara-github committed Aug 19, 2020
1 parent 1293fa8 commit 4de8092
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
22 changes: 14 additions & 8 deletions test/e2e_clutz_dts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
* found in the LICENSE file at https://angular.io/license
*/

/**
* @fileoverview Type-checks all d.ts files found in the test tree.
* This verifies that the d.ts we generate as a product of compilation
* are valid.
*
* In general, .d.ts are generated by the TypeScript compiler, not tsickle, but
* we do some transforms of those .d.ts files for Clutz interop (see
* src/clutz.ts) and this test helps verify those transforms generate valid
* compileable output.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as ts from 'typescript';
Expand All @@ -16,15 +27,10 @@ describe('clutz dts', () => {
testSupport.addDiffMatchers();
});
it('produces a valid .d.ts', () => {
const tests = testSupport.goldenTests().filter(t => t.isDeclarationTest);

const dtsSources = new Map<string, string>();

for (const test of tests) {
for (const tsPath of test.allDtsPaths()) {
const tsSource = fs.readFileSync(tsPath, 'utf-8');
dtsSources.set(tsPath, tsSource);
}
for (const tsPath of testSupport.allDtsPaths()) {
const tsSource = fs.readFileSync(tsPath, 'utf-8');
dtsSources.set(tsPath, tsSource);
}

const program = testSupport.createProgram(dtsSources);
Expand Down
16 changes: 8 additions & 8 deletions test/test_support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,6 @@ export class GoldenFileTest {
.map(p => path.join(this.root, p));
}

/**
* Gets all .d.ts files in the test, input or output, as absolute paths.
*/
allDtsPaths(): string[] {
return this.tsPaths.filter(p => p.endsWith('.d.ts'))
.map(p => path.join(this.root, p));
}

/**
* Gets the absolute paths to the expected .js outputs of the test.
*/
Expand Down Expand Up @@ -271,6 +263,14 @@ export function goldenTests(): GoldenFileTest[] {
return tests;
}

/**
* Returns absolute paths to every .d.ts in the test_files tree, for
* verification by the e2e_clutz_dts_test.
*/
export function allDtsPaths(): string[] {
return glob.sync(path.join(rootDir(), 'test_files', '**/*.d.ts'));
}

/**
* Reads the files from the file system and returns a map from filePaths to
* file contents.
Expand Down
16 changes: 16 additions & 0 deletions test_files/clutz_user.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @fileoverview Tests that renamed exports get emitted with the correct Clutz
* alias names. This is simulating the kinds of references Clutz wants to
* generate to refer to types in tsickle.
*
* This file is tested by the e2e_clutz_dts test and passes as long as it
* type-checks.
*/

export {};

declare const moduleInternalName: typeof ಠ_ಠ.clutz
.module$contents$test_files$reexport$declaration$renamed_export_MOTHER;

declare const exportedName: typeof ಠ_ಠ.clutz
.module$exports$test_files$reexport$declaration$renamed_export.MOTHER;
9 changes: 0 additions & 9 deletions test_files/reexport.declaration/clutz_user.d.ts

This file was deleted.

0 comments on commit 4de8092

Please sign in to comment.