Skip to content

Commit

Permalink
Add additional integration test for sync/async imports
Browse files Browse the repository at this point in the history
  • Loading branch information
marcins committed Jul 23, 2023
1 parent f32bdf0 commit 43d98d0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default () => {
return Promise.all([
import('./uses-static-component').then(c => {
return c.default()();
}),
import('./uses-static-component-async').then(c => {
return c.default();
}).then(s => {
return s();
})]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => "static component";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default async () => {
const m = await import('./static-component');
return m.default;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import staticComponent from "./static-component"
export default () => {
return staticComponent;
}
36 changes: 36 additions & 0 deletions packages/core/integration-tests/test/lazy-compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getNextBuild,
assertBundles,
removeDistDirectory,
run,
} from '@parcel/test-utils';

const findBundle = (bundleGraph, nameRegex) => {
Expand Down Expand Up @@ -84,4 +85,39 @@ describe('lazy compile', function () {
// Ensure the files match the bundle graph - lazy-2 should've been produced as it was requested
assert(await distDirIncludes(['index.js', /^lazy-1\./, /^lazy-2\./]));
});

it('should lazy compile properly when same module is used sync/async', async () => {
const b = await bundler(
path.join(__dirname, '/integration/lazy-compile/index-sync-async.js'),
{
shouldBuildLazily: true,
mode: 'development',
shouldContentHash: false,
},
);

await removeDistDirectory();

const subscription = await b.watch();
let result = await getNextBuild(b);
result = await result.requestBundle(
findBundle(result.bundleGraph, /^index-sync-async\./),
);
result = await result.requestBundle(
findBundle(result.bundleGraph, /^uses-static-component\./),
);
result = await result.requestBundle(
findBundle(result.bundleGraph, /^uses-static-component-async\./),
);
result = await result.requestBundle(
findBundle(result.bundleGraph, /^static-component\./),
);

let output = await run(result.bundleGraph);
assert.deepEqual(await output.default(), [
'static component',
'static component',
]);
subscription.unsubscribe();
});
});

0 comments on commit 43d98d0

Please sign in to comment.