-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add failing integration test for lazy compilation
- Loading branch information
Showing
8 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
packages/core/integration-tests/test/integration/lazy-compile/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<script src="./index.js" type="module"></script> | ||
</body> | ||
</html> |
7 changes: 7 additions & 0 deletions
7
packages/core/integration-tests/test/integration/lazy-compile/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
async function main() { | ||
const m = await import('./lazy-1'); | ||
await import('./parallel-lazy-1'); | ||
return 'sup'; //m.default(); | ||
} | ||
|
||
main(); |
4 changes: 4 additions & 0 deletions
4
packages/core/integration-tests/test/integration/lazy-compile/lazy-1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default async () => { | ||
const { world } = await import('./lazy-2'); | ||
return `Hello ${world}`; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/core/integration-tests/test/integration/lazy-compile/lazy-2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const world = 'world'; |
3 changes: 3 additions & 0 deletions
3
packages/core/integration-tests/test/integration/lazy-compile/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"private": true | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/core/integration-tests/test/integration/lazy-compile/parallel-lazy-1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default async () => { | ||
const m = await import('./parallel-lazy-2'); | ||
return m.default; | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/core/integration-tests/test/integration/lazy-compile/parallel-lazy-2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'parallel lazy 2'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import assert from 'assert'; | ||
import path from 'path'; | ||
import { | ||
bundler, | ||
outputFS, | ||
distDir, | ||
getNextBuild, | ||
assertBundles, | ||
removeDistDirectory, | ||
} from '@parcel/test-utils'; | ||
|
||
const findBundle = (bundleGraph, nameRegex) => { | ||
return bundleGraph.getBundles().find(b => nameRegex.test(b.name)); | ||
}; | ||
|
||
const distDirIncludes = async matches => { | ||
const files = await outputFS.readdir(distDir); | ||
for (const match of matches) { | ||
if (typeof match === 'string') { | ||
if (!files.some(file => file === match)) { | ||
throw new Error( | ||
`No file matching ${match} was found in ${files.join(', ')}`, | ||
); | ||
} | ||
} else { | ||
if (!files.some(file => match.test(file))) { | ||
throw new Error( | ||
`No file matching ${match} was found in ${files.join(', ')}`, | ||
); | ||
} | ||
} | ||
} | ||
return true; | ||
}; | ||
|
||
describe('lazy compile', function () { | ||
it('should lazy compile', async function () { | ||
const b = await bundler( | ||
path.join(__dirname, '/integration/lazy-compile/index.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.js/), | ||
); | ||
result = await result.requestBundle( | ||
findBundle(result.bundleGraph, /^lazy-1/), | ||
); | ||
result = await result.requestBundle( | ||
findBundle(result.bundleGraph, /^lazy-2/), | ||
); | ||
|
||
// Expect the bundle graph to contain the whole nest of lazy from `lazy-1`, but not | ||
// `parallel-lazy-1` which wasn't requested. | ||
assertBundles(result.bundleGraph, [ | ||
{ | ||
assets: ['index.js', 'bundle-url.js', 'cacheLoader.js', 'js-loader.js'], | ||
}, | ||
{ | ||
assets: ['lazy-1.js', 'esmodule-helpers.js'], | ||
}, | ||
{ | ||
assets: ['lazy-2.js'], | ||
}, | ||
{ | ||
assets: ['parallel-lazy-1.js'], | ||
}, | ||
]); | ||
|
||
subscription.unsubscribe(); | ||
|
||
// 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\./])); | ||
}); | ||
}); |