Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
WIP - Add webpack 4 tree shaking test
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinGrandon committed Mar 20, 2018
1 parent 3582b0c commit 4c8588c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/cli/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,29 @@ test('`fusion build` with dynamic imports', async t => {
);
t.end();
});

test('`fusion build` tree shaking', async t => {
const dir = path.resolve(__dirname, '../fixtures/tree-shaking');
await cmd(`build --dir=${dir}`);

const serverMain = path.resolve(
dir,
`.fusion/dist/development/server/server-main.js`
);
const clientMain = path.resolve(
dir,
`.fusion/dist/development/client/client-main.js`
);

t.ok(
!fs.readFileSync(serverMain, 'utf-8').includes('./src/browserPlugin.js'),
'should not include browserPlugin in node'
);

t.ok(
!fs.readFileSync(clientMain, 'utf-8').includes('./src/nodePlugin.js'),
'should not include nodePlugin in browser'
);

t.end();
});
7 changes: 7 additions & 0 deletions test/fixtures/tree-shaking/src/browserPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {createPlugin} from 'fusion-core';

export default createPlugin({
provides() {
console.log('executing browser plugin');
},
});
5 changes: 5 additions & 0 deletions test/fixtures/tree-shaking/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ import readline from 'readline';
import repl from 'repl';
import tls from 'tls';

import browserPlugin from './browserPlugin.js';
import nodePlugin from './nodePlugin.js';

export default async function() {
const app = new App('element', el => el);
__BROWSER__ && app.register(browserPlugin);
__NODE__ && app.register(nodePlugin);
__NODE__ &&
app.middleware((ctx, next) => {
if (ctx.url === '/fs') {
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/tree-shaking/src/nodePlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {createPlugin} from 'fusion-core';

export default createPlugin({
provides() {
console.log('executing node plugin');
},
});

0 comments on commit 4c8588c

Please sign in to comment.