Skip to content

Commit

Permalink
Add in some functional tests, using Lerna to manage the dependencies …
Browse files Browse the repository at this point in the history
…of each test 'repo'
  • Loading branch information
stephencookdev committed Mar 8, 2018
1 parent 1818c22 commit 7ecb8b8
Show file tree
Hide file tree
Showing 25 changed files with 35,521 additions and 2,718 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
node_modules
lerna-debug.log
3 changes: 3 additions & 0 deletions .npmignore
@@ -0,0 +1,3 @@
examples/
.prettierrc
__tests__/
4 changes: 4 additions & 0 deletions __tests__/common/app.js
@@ -0,0 +1,4 @@
require("./constants");
require("./styles.css");

console.log("Some javascript", FOO);
1 change: 1 addition & 0 deletions __tests__/common/constants.js
@@ -0,0 +1 @@
const a = 1;
70 changes: 70 additions & 0 deletions __tests__/common/smp.test.js
@@ -0,0 +1,70 @@
const SpeedMeasurePlugin = require("../../..");
const webpack = require("webpack");
const { readFileSync } = require("fs");
const webpackConfig = require("./webpack.config");

const genSmpWebpackConfig = smp =>
smp.wrap(
Object.assign({}, webpackConfig, {
output: {
path: webpackConfig.output.path + "/_smp_" + new Date().getTime(),
},
})
);

const runWebpack = config =>
new Promise((resolve, reject) => {
webpack(config, (err, stats) => {
if (err || stats.hasErrors()) return reject(err || stats);
resolve(readFileSync(config.output.path + "/bundle.js").toString());
});
});

describe("smp - " + __dirname.split("/").pop(), () => {
let distApp;
beforeAll(() => runWebpack(webpackConfig).then(file => (distApp = file)));

describe("vanilla config", () => {
let smpOutput;
let smpDistApp;
const smp = new SpeedMeasurePlugin({
outputTarget: output => (smpOutput = output),
});
const smpWebpackConfig = genSmpWebpackConfig(smp);

beforeAll(() =>
runWebpack(smpWebpackConfig).then(file => (smpDistApp = file))
);

it("should generate the same app.js content", () => {
expect(smpDistApp).toEqual(distApp);
});

it("should generate the same app.js content after 2 runs", () => {
const dupSmpWebpackConfig = genSmpWebpackConfig(smp);

return runWebpack(dupSmpWebpackConfig).then(dupSmpDistApp => {
expect(dupSmpDistApp).toEqual(smpDistApp);
expect(dupSmpDistApp).toEqual(distApp);
});
});

it("should state the time taken overall", () => {
expect(smpOutput).toMatch(
/General output time took .*([0-9]+ mins? )?[0-9]+(\.[0-9]+)? secs/
);
});

it("should state the time taken by the plugins", () => {
expect(smpOutput).toMatch(
/DefinePlugin.* took .*([0-9]+ mins? )?[0-9]+(\.[0-9]+)? secs/
);
});

it("should state the time taken by the loaders", () => {
expect(smpOutput).toMatch(
/babel-loader.* took .*([0-9]+ mins? )?[0-9]+(\.[0-9]+)? secs.*\n\s+module count\s+= [0-9]+/
);
});
});
});
3 changes: 3 additions & 0 deletions __tests__/common/styles.css
@@ -0,0 +1,3 @@
.a {
color: red;
}
5 changes: 5 additions & 0 deletions __tests__/setups/.gitignore
@@ -0,0 +1,5 @@
app.js
constants.js
styles.css
smp.test.js
dist
3 changes: 3 additions & 0 deletions __tests__/setups/.prettierrc
@@ -0,0 +1,3 @@
{
"trailingComma": "es5"
}

0 comments on commit 7ecb8b8

Please sign in to comment.