Skip to content

Commit 71f906a

Browse files
Merge pull request #24 from stephencookdev/feature/tests
Functional tests
2 parents 3880d43 + 7ecb8b8 commit 71f906a

25 files changed

Lines changed: 35521 additions & 2718 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
lerna-debug.log

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
examples/
2+
.prettierrc
3+
__tests__/

__tests__/common/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require("./constants");
2+
require("./styles.css");
3+
4+
console.log("Some javascript", FOO);

__tests__/common/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const a = 1;

__tests__/common/smp.test.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const SpeedMeasurePlugin = require("../../..");
2+
const webpack = require("webpack");
3+
const { readFileSync } = require("fs");
4+
const webpackConfig = require("./webpack.config");
5+
6+
const genSmpWebpackConfig = smp =>
7+
smp.wrap(
8+
Object.assign({}, webpackConfig, {
9+
output: {
10+
path: webpackConfig.output.path + "/_smp_" + new Date().getTime(),
11+
},
12+
})
13+
);
14+
15+
const runWebpack = config =>
16+
new Promise((resolve, reject) => {
17+
webpack(config, (err, stats) => {
18+
if (err || stats.hasErrors()) return reject(err || stats);
19+
resolve(readFileSync(config.output.path + "/bundle.js").toString());
20+
});
21+
});
22+
23+
describe("smp - " + __dirname.split("/").pop(), () => {
24+
let distApp;
25+
beforeAll(() => runWebpack(webpackConfig).then(file => (distApp = file)));
26+
27+
describe("vanilla config", () => {
28+
let smpOutput;
29+
let smpDistApp;
30+
const smp = new SpeedMeasurePlugin({
31+
outputTarget: output => (smpOutput = output),
32+
});
33+
const smpWebpackConfig = genSmpWebpackConfig(smp);
34+
35+
beforeAll(() =>
36+
runWebpack(smpWebpackConfig).then(file => (smpDistApp = file))
37+
);
38+
39+
it("should generate the same app.js content", () => {
40+
expect(smpDistApp).toEqual(distApp);
41+
});
42+
43+
it("should generate the same app.js content after 2 runs", () => {
44+
const dupSmpWebpackConfig = genSmpWebpackConfig(smp);
45+
46+
return runWebpack(dupSmpWebpackConfig).then(dupSmpDistApp => {
47+
expect(dupSmpDistApp).toEqual(smpDistApp);
48+
expect(dupSmpDistApp).toEqual(distApp);
49+
});
50+
});
51+
52+
it("should state the time taken overall", () => {
53+
expect(smpOutput).toMatch(
54+
/General output time took .*([0-9]+ mins? )?[0-9]+(\.[0-9]+)? secs/
55+
);
56+
});
57+
58+
it("should state the time taken by the plugins", () => {
59+
expect(smpOutput).toMatch(
60+
/DefinePlugin.* took .*([0-9]+ mins? )?[0-9]+(\.[0-9]+)? secs/
61+
);
62+
});
63+
64+
it("should state the time taken by the loaders", () => {
65+
expect(smpOutput).toMatch(
66+
/babel-loader.* took .*([0-9]+ mins? )?[0-9]+(\.[0-9]+)? secs.*\n\s+module count\s+= [0-9]+/
67+
);
68+
});
69+
});
70+
});

__tests__/common/styles.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.a {
2+
color: red;
3+
}

__tests__/setups/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
app.js
2+
constants.js
3+
styles.css
4+
smp.test.js
5+
dist

__tests__/setups/.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"trailingComma": "es5"
3+
}

0 commit comments

Comments
 (0)