|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | import {TypesFetcher} from '../typescript-worker/types-fetcher.js'; |
| 8 | +import ts from '../internal/typescript.js'; |
8 | 9 | import {ImportMapResolver} from '../typescript-worker/import-map-resolver.js'; |
9 | 10 | import {configureFakeCdn} from './worker-test-util.js'; |
10 | 11 | import {assert} from '@esm-bundle/chai'; |
@@ -571,10 +572,78 @@ suite('types fetcher', () => { |
571 | 572 | }); |
572 | 573 | }); |
573 | 574 |
|
574 | | - test('tslibs', async () => { |
| 575 | + test('tslibs default to the bundled TypeScript version', async () => { |
575 | 576 | const sourceTexts: string[] = []; |
576 | 577 | const tsLibs = ['es2020', 'DOM']; |
577 | 578 | const packageJson: PackageJson = {}; |
| 579 | + const cdnData: CdnData = { |
| 580 | + typescript: { |
| 581 | + versions: { |
| 582 | + [ts.version]: { |
| 583 | + files: { |
| 584 | + 'lib/lib.es2020.d.ts': { |
| 585 | + // References are the same as imports from our perspective. |
| 586 | + content: `/// <reference lib="es2020.promise" />`, |
| 587 | + }, |
| 588 | + 'lib/lib.es2020.promise.d.ts': { |
| 589 | + content: `interface PromiseConstructor { }`, |
| 590 | + }, |
| 591 | + // Note standard lib files are always lower-case. |
| 592 | + 'lib/lib.dom.d.ts': { |
| 593 | + content: `interface HTMLElement { }`, |
| 594 | + }, |
| 595 | + }, |
| 596 | + }, |
| 597 | + // TypeScript 7 doesn't have the lib files. We must not try to load |
| 598 | + // the libs from here just because it is the latest version. |
| 599 | + '7.0.0': { |
| 600 | + files: {}, |
| 601 | + }, |
| 602 | + }, |
| 603 | + }, |
| 604 | + }; |
| 605 | + const expectedDependencyGraph: ExpectedDependencyGraph = { |
| 606 | + root: { |
| 607 | + typescript: ts.version, |
| 608 | + }, |
| 609 | + deps: {}, |
| 610 | + }; |
| 611 | + const expectedLayout: NodeModulesDirectory = { |
| 612 | + typescript: { |
| 613 | + version: ts.version, |
| 614 | + nodeModules: {}, |
| 615 | + }, |
| 616 | + }; |
| 617 | + const expectedFiles = new Map([ |
| 618 | + [ |
| 619 | + 'typescript/lib/lib.es2020.d.ts', |
| 620 | + `/// <reference lib="es2020.promise" />`, |
| 621 | + ], |
| 622 | + [ |
| 623 | + 'typescript/lib/lib.es2020.promise.d.ts', |
| 624 | + `interface PromiseConstructor { }`, |
| 625 | + ], |
| 626 | + ['typescript/lib/lib.dom.d.ts', `interface HTMLElement { }`], |
| 627 | + ]); |
| 628 | + await checkTypesFetcher({ |
| 629 | + sourceTexts, |
| 630 | + tsLibs, |
| 631 | + packageJson, |
| 632 | + cdnData, |
| 633 | + expectedFiles, |
| 634 | + expectedDependencyGraph, |
| 635 | + expectedLayout, |
| 636 | + }); |
| 637 | + }); |
| 638 | + |
| 639 | + test('tslibs use the TypeScript version from package.json', async () => { |
| 640 | + const sourceTexts: string[] = []; |
| 641 | + const tsLibs = ['es2020', 'DOM']; |
| 642 | + const packageJson: PackageJson = { |
| 643 | + dependencies: { |
| 644 | + typescript: '4.3.5', |
| 645 | + }, |
| 646 | + }; |
578 | 647 | const cdnData: CdnData = { |
579 | 648 | typescript: { |
580 | 649 | versions: { |
|
0 commit comments