Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test for preloadModules option #1399

Merged
merged 2 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion plugins/plugin-optimize/test/__snapshots__/plugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,47 @@ exports[`@snowpack/plugin-optimize minimal - no minification: fs.writeFileSync 1
exports[`@snowpack/plugin-optimize minimal - no options: console.log 1`] = ``;

exports[`@snowpack/plugin-optimize minimal - no options: fs.writeFileSync 1`] = `
FILE: stubs/minimal/esm_example.js
export default function e(){return console.log("example"),1}


--------------------------------------------------------------------------------

FILE: stubs/minimal/index.html
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Minimal test</title><link rel="stylesheet" href="style.css"></head><body><script type="module" src="index.js"></script></body></html>

--------------------------------------------------------------------------------

FILE: stubs/minimal/index.js
(()=>{function n(o){console.log(o)}n("test")})();
import"./esm_example.js";(()=>{function e(m){console.log(m)}e("test")})();


--------------------------------------------------------------------------------

FILE: stubs/minimal/style.css
body{border:1px solid red}
`;

exports[`@snowpack/plugin-optimize no HTML minification, with preloadModules: console.log 1`] = ``;

exports[`@snowpack/plugin-optimize no HTML minification, with preloadModules: fs.writeFileSync 1`] = `
FILE: stubs/minimal/esm_example.js
export default function e(){return console.log("example"),1}


--------------------------------------------------------------------------------

FILE: stubs/minimal/index.html
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Minimal test</title><link rel="stylesheet" href="style.css"> <!-- @snowpack/plugin-optimize] Add modulepreload to improve unbundled load performance (More info: https://developers.google.com/web/updates/2017/12/modulepreload) -->
<link rel="modulepreload" href="/esm_example.js" />
</head><body><script type="module" src="index.js"></script> <!-- [@snowpack/plugin-optimize] modulepreload fallback for browsers that do not support it yet -->
<script type="module" src="/esm_example.js"></script>
</body></html>

--------------------------------------------------------------------------------

FILE: stubs/minimal/index.js
import"./esm_example.js";(()=>{function e(m){console.log(m)}e("test")})();


--------------------------------------------------------------------------------
Expand Down
18 changes: 18 additions & 0 deletions plugins/plugin-optimize/test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,22 @@ describe('@snowpack/plugin-optimize', () => {
expect(fs.writeFileSync).toMatchSnapshot('fs.writeFileSync');
expect(console.log).toMatchSnapshot('console.log');
});

it('no HTML minification, with preloadModules', async () => {
const pluginInstance = plugin(
{
buildOptions: {},
},
{
minifyHTML: false,
preloadModules: true
})

await pluginInstance.optimize({
buildDirectory: path.resolve(__dirname, 'stubs/minimal/'),
});

expect(fs.writeFileSync).toMatchSnapshot('fs.writeFileSync');
expect(console.log).toMatchSnapshot('console.log');
});
});
4 changes: 4 additions & 0 deletions plugins/plugin-optimize/test/stubs/minimal/esm_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default function esm_example() {
console.log('example')
return 1
}
2 changes: 2 additions & 0 deletions plugins/plugin-optimize/test/stubs/minimal/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import esm_example from './esm_example.js'

(() => {
function n(o) {
console.log(o);
Expand Down