mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[type-summarizer/integration] fix flaky tests (#127038)
This commit is contained in:
parent
73f7ac419f
commit
004f0d4daa
8 changed files with 27 additions and 19 deletions
|
@ -17,6 +17,8 @@ import { tryReadFile } from './helpers/fs';
|
|||
import { parseJson } from './helpers/json';
|
||||
import { isNodeModule } from './is_node_module';
|
||||
|
||||
type SourceMapConsumerEntry = [ts.SourceFile, BasicSourceMapConsumer | undefined];
|
||||
|
||||
export class SourceMapper {
|
||||
static async forSourceFiles(
|
||||
log: Logger,
|
||||
|
@ -24,10 +26,8 @@ export class SourceMapper {
|
|||
repoRelativePackageDir: string,
|
||||
sourceFiles: readonly ts.SourceFile[]
|
||||
) {
|
||||
const consumers = new Map<ts.SourceFile, BasicSourceMapConsumer | undefined>();
|
||||
|
||||
await Promise.all(
|
||||
sourceFiles.map(async (sourceFile) => {
|
||||
const entries = await Promise.all(
|
||||
sourceFiles.map(async (sourceFile): Promise<undefined | SourceMapConsumerEntry> => {
|
||||
if (isNodeModule(dtsDir, sourceFile.fileName)) {
|
||||
return;
|
||||
}
|
||||
|
@ -35,8 +35,7 @@ export class SourceMapper {
|
|||
const text = sourceFile.getText();
|
||||
const match = text.match(/^\/\/#\s*sourceMappingURL=(.*)/im);
|
||||
if (!match) {
|
||||
consumers.set(sourceFile, undefined);
|
||||
return;
|
||||
return [sourceFile, undefined];
|
||||
}
|
||||
|
||||
const relSourceFile = Path.relative(process.cwd(), sourceFile.fileName);
|
||||
|
@ -50,11 +49,16 @@ export class SourceMapper {
|
|||
}
|
||||
|
||||
const json = parseJson(sourceJson, `source map at [${relSourceMapPath}]`);
|
||||
consumers.set(sourceFile, await new SourceMapConsumer(json));
|
||||
log.debug('loaded sourcemap for', relSourceFile);
|
||||
return [sourceFile, await new SourceMapConsumer(json)];
|
||||
})
|
||||
);
|
||||
|
||||
const consumers = new Map(entries.filter((e): e is SourceMapConsumerEntry => !!e));
|
||||
log.debug(
|
||||
'loaded sourcemaps for',
|
||||
Array.from(consumers.keys()).map((s) => Path.relative(process.cwd(), s.fileName))
|
||||
);
|
||||
|
||||
return new SourceMapper(consumers, repoRelativePackageDir);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ it('prints basic class correctly', async () => {
|
|||
}
|
||||
`);
|
||||
expect(output.logs).toMatchInlineSnapshot(`
|
||||
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
|
||||
"debug loaded sourcemaps for [ 'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts' ]
|
||||
debug Ignoring 1 global declarations for \\"Record\\"
|
||||
debug Ignoring 5 global declarations for \\"Promise\\"
|
||||
"
|
||||
|
|
|
@ -74,8 +74,10 @@ it('prints the function declaration, including comments', async () => {
|
|||
}
|
||||
`);
|
||||
expect(result.logs).toMatchInlineSnapshot(`
|
||||
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/bar.d.ts
|
||||
debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
|
||||
"debug loaded sourcemaps for [
|
||||
'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/bar.d.ts',
|
||||
'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts'
|
||||
]
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
|
|
@ -52,7 +52,7 @@ it('output type links to named import from node modules', async () => {
|
|||
}
|
||||
`);
|
||||
expect(output.logs).toMatchInlineSnapshot(`
|
||||
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
|
||||
"debug loaded sourcemaps for [ 'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts' ]
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
@ -84,7 +84,7 @@ it('output type links to default import from node modules', async () => {
|
|||
}
|
||||
`);
|
||||
expect(output.logs).toMatchInlineSnapshot(`
|
||||
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
|
||||
"debug loaded sourcemaps for [ 'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts' ]
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
|
|
@ -55,7 +55,7 @@ it('prints the whole interface, including comments', async () => {
|
|||
}
|
||||
`);
|
||||
expect(result.logs).toMatchInlineSnapshot(`
|
||||
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
|
||||
"debug loaded sourcemaps for [ 'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts' ]
|
||||
debug Ignoring 5 global declarations for \\"Promise\\"
|
||||
"
|
||||
`);
|
||||
|
|
|
@ -59,9 +59,11 @@ it('collects references from source files which contribute to result', async ()
|
|||
}
|
||||
`);
|
||||
expect(result.logs).toMatchInlineSnapshot(`
|
||||
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/files/foo.d.ts
|
||||
debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/files/index.d.ts
|
||||
debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
|
||||
"debug loaded sourcemaps for [
|
||||
'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/files/foo.d.ts',
|
||||
'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/files/index.d.ts',
|
||||
'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts'
|
||||
]
|
||||
debug Ignoring 5 global declarations for \\"Promise\\"
|
||||
debug Ignoring 4 global declarations for \\"Symbol\\"
|
||||
debug Ignoring 2 global declarations for \\"Component\\"
|
||||
|
|
|
@ -36,7 +36,7 @@ it('prints basic type alias', async () => {
|
|||
}
|
||||
`);
|
||||
expect(output.logs).toMatchInlineSnapshot(`
|
||||
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
|
||||
"debug loaded sourcemaps for [ 'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts' ]
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
|
|
@ -62,7 +62,7 @@ it('prints basic variable exports with sourcemaps', async () => {
|
|||
}
|
||||
`);
|
||||
expect(output.logs).toMatchInlineSnapshot(`
|
||||
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
|
||||
"debug loaded sourcemaps for [ 'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts' ]
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue