Skip to content

Commit 543cec8

Browse files
committed
test: add multiecompiler test
1 parent f97eff2 commit 543cec8

File tree

12 files changed

+136
-2
lines changed

12 files changed

+136
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ const options = { ... };
6262

6363
module.exports = {
6464
// an example entry definition
65-
output: '/myapp/dist',
65+
output: {
66+
path: '/myapp/dist' // ← important: this must be an absolute path!
67+
}
6668
...
6769
plugins: [
6870
new WebpackPluginRamdisk(options)

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"commitmsg": "commitlint -e $GIT_PARAMS",
2121
"lint": "eslint --fix --cache lib test",
2222
"lint-staged": "lint-staged",
23+
"pretest": "del test/fixtures/multi/output test/fixtures/simple/output",
2324
"security": "npm audit",
2425
"test": "ava"
2526
},
@@ -40,6 +41,7 @@
4041
"@commitlint/cli": "^8.0.0",
4142
"@commitlint/config-conventional": "^8.0.0",
4243
"ava": "^2.1.0",
44+
"del-cli": "^2.0.0",
4345
"eslint": "^6.0.1",
4446
"eslint-config-shellscape": "^2.0.2",
4547
"lint-staged": "^8.1.0",
@@ -63,7 +65,9 @@
6365
"webpack"
6466
],
6567
"ava": {
66-
"files": ["!**/fixtures/**"]
68+
"files": [
69+
"!**/fixtures/**"
70+
]
6771
},
6872
"pre-commit": "lint-staged",
6973
"lint-staged": {

test/fixtures/multi/app.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require('./component');
2+
3+
if (module.hot) {
4+
module.hot.accept((err) => {
5+
if (err) {
6+
console.error('HMR', err);
7+
}
8+
});
9+
}
10+
11+
// uncomment to produce a build error
12+
// if (!window) {
13+
// require('tests');
14+
// }
15+
16+
// uncomment to produce a build warning
17+
// console.log(require);

test/fixtures/multi/component.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const main = document.querySelector('main');
2+
main.innerHTML = 'main';

test/fixtures/multi/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype>
2+
<html>
3+
<head>
4+
<title>fixture: multicompiler</title>
5+
</head>
6+
<body>
7+
<main></main>
8+
<div id="worker"></div>
9+
<script src="/output/dist-app.js"></script>
10+
<script src="/output/dist-worker.js"></script>
11+
</body>
12+
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const { resolve } = require('path');
2+
3+
const { WebpackPluginRamdisk } = require('../../../lib/');
4+
5+
module.exports = [
6+
{
7+
context: __dirname,
8+
entry: './app.js',
9+
mode: 'development',
10+
output: {
11+
filename: './dist-app.js',
12+
path: '/output',
13+
publicPath: 'output/'
14+
},
15+
plugins: [new WebpackPluginRamdisk({ name: 'multiconfig' })]
16+
},
17+
{
18+
context: __dirname,
19+
entry: './worker.js',
20+
mode: 'development',
21+
output: {
22+
filename: './dist-worker.js',
23+
path: resolve(__dirname, './output'),
24+
publicPath: 'output/'
25+
}
26+
}
27+
];

test/fixtures/multi/work.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const main = document.querySelector('#worker');
2+
main.innerHTML = 'worker';
3+
4+
// console.log(require);

test/fixtures/multi/worker.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require('./work');
2+
3+
if (module.hot) {
4+
module.hot.accept((err) => {
5+
if (err) {
6+
console.error('HMR', err);
7+
}
8+
});
9+
}
10+
11+
// uncomment to produce a build error
12+
// if (!window) {
13+
// require('tests');
14+
// }
15+
16+
// uncomment to produce a build warning
17+
// console.log(require);

test/multi.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { existsSync: exists } = require('fs');
2+
const { join } = require('path');
3+
4+
const test = require('ava');
5+
const execa = require('execa');
6+
7+
const { WebpackPluginRamdisk } = require('../lib');
8+
9+
const detatch = WebpackPluginRamdisk.cleanup;
10+
11+
test('multi config', (t) => {
12+
const cwd = join(__dirname, 'fixtures/multi');
13+
const { stdout } = execa.commandSync(`npx wp`, { cwd });
14+
const [, outputPath] = stdout.match(/written to (.+)\n?/);
15+
const [diskPath] = outputPath.match(/((.+)multiconfig)/);
16+
17+
t.snapshot(outputPath.replace(/mnt|Volumes/, '[mount]'));
18+
t.snapshot(diskPath.replace(/mnt|Volumes/, '[mount]'));
19+
20+
t.true(exists(join(outputPath, 'dist-app.js')));
21+
t.true(exists(join(__dirname, 'fixtures/multi/output/dist-worker.js')));
22+
23+
detatch(diskPath);
24+
});

0 commit comments

Comments
 (0)