Skip to content

Commit

Permalink
Merge branch 'main' into pr/mateenagy/179
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jan 11, 2024
2 parents 7164671 + d212da8 commit 8edaa84
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions test/imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,32 @@ staticTests['import { foo, type Foo } from "foo"'] = {
namedImports: { foo: "foo" },
};

staticTests[
`
// import { foo } from "foo"
import { too } from "too"
/**
* import { zoo } from "zoo"
*/
const start = '/*'
import { ioo } from "ioo"
const end = '*/'
`
] = [
{
specifier: "too",
type: "static",
namedImports: { too: "too" },
},
{
specifier: "ioo",
type: "static",
namedImports: { ioo: "ioo" },
},
];

// -- Dynamic import --
const dynamicTests = {
'const { test, /* here */, another, } = await import ( "module-name" );': {
Expand All @@ -153,6 +179,8 @@ const dynamicTests = {
'import("abc").then(r => r.default)': {
expression: '"abc"',
},
'// import("abc").then(r => r.default)': [],
'/* import("abc").then(r => r.default) */': [],
};

const TypeTests = {
Expand Down Expand Up @@ -237,10 +265,12 @@ describe("findDynamicImports", () => {
for (const [input, test] of Object.entries(dynamicTests)) {
it(input.replace(/\n/g, "\\n"), () => {
const matches = findDynamicImports(input);
expect(matches.length).to.equal(1);
expect(matches.length).to.equal(Array.isArray(test) ? test.length : 1);
const match = matches[0];
expect(match.type).to.equal("dynamic");
expect(match.expression.trim()).to.equal(test.expression);
if (match) {
expect(match.type).to.equal("dynamic");
expect(match.expression.trim()).to.equal(test.expression);
}
});
}
});
Expand Down

0 comments on commit 8edaa84

Please sign in to comment.