Skip to content

Commit

Permalink
chore: add fixture and test for #104
Browse files Browse the repository at this point in the history
  • Loading branch information
kravetsone committed Jan 5, 2025
1 parent d4206d0 commit db837d0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,21 @@ export const fixtureDynamicImports: FileTree = {
},
},
};

// https://github.com/privatenumber/pkgroll/issues/104
export const fixtureDynamicImportsError: FileTree = {
'package.json': createPackageJson({
main: './dist/dynamic-imports.js',
}),
src: {
'dynamic-imports.js': outdent`
function importModule(path) {
// who knows what will be imported here?
return import(path);
}
importModule('./should-fail.js');
`,
'should-fail.js': 'console.log(123)',
},
};
22 changes: 22 additions & 0 deletions tests/specs/builds/output-commonjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createFixture } from 'fs-fixture';
import { pkgroll } from '../../utils.js';
import {
packageFixture, createPackageJson, createTsconfigJson, fixtureDynamicImports,
fixtureDynamicImportsError,
} from '../../fixtures.js';

export default testSuite(({ describe }, nodePath: string) => {
Expand Down Expand Up @@ -204,5 +205,26 @@ export default testSuite(({ describe }, nodePath: string) => {
expect(files[1]).toMatch(/^bbb-/);
expect(files[2]).toMatch(/^ccc-/);
});

// https://github.com/privatenumber/pkgroll/issues/104
test('dynamic imports warning', async () => {
await using fixture = await createFixture({
...fixtureDynamicImportsError,
'package.json': createPackageJson({
exports: './dist/dynamic-imports.cjs',
}),
});

const pkgrollProcess = await pkgroll([], {
cwd: fixture.path,
nodePath,
});

expect(pkgrollProcess.exitCode).toBe(0);
expect(pkgrollProcess.stderr).toContain('[plugin rollup-plugin-dynamic-import-variables]');

const content = await fixture.readFile('dist/dynamic-imports.cjs', 'utf8');
expect(content).toMatch('import(');
});
});
});
22 changes: 22 additions & 0 deletions tests/specs/builds/output-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createFixture } from 'fs-fixture';
import { pkgroll } from '../../utils.js';
import {
packageFixture, createPackageJson, createTsconfigJson, fixtureDynamicImports,
fixtureDynamicImportsError,
} from '../../fixtures.js';

export default testSuite(({ describe }, nodePath: string) => {
Expand Down Expand Up @@ -272,5 +273,26 @@ export default testSuite(({ describe }, nodePath: string) => {
expect(files[1]).toMatch(/^bbb-/);
expect(files[2]).toMatch(/^ccc-/);
});

// https://github.com/privatenumber/pkgroll/issues/104
test('dynamic imports warning', async () => {
await using fixture = await createFixture({
...fixtureDynamicImportsError,
'package.json': createPackageJson({
exports: './dist/dynamic-imports.mjs',
}),
});

const pkgrollProcess = await pkgroll([], {
cwd: fixture.path,
nodePath,
});

expect(pkgrollProcess.exitCode).toBe(0);
expect(pkgrollProcess.stderr).toContain('[plugin rollup-plugin-dynamic-import-variables]');

const content = await fixture.readFile('dist/dynamic-imports.mjs', 'utf8');
expect(content).toMatch('import(');
});
});
});

0 comments on commit db837d0

Please sign in to comment.