Skip to content

Commit 415861e

Browse files
test: Add a script to test the demo on webpack 3 and 4 (#17)
1 parent 23c367a commit 415861e

File tree

4 files changed

+78
-5
lines changed

4 files changed

+78
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ This project's Git repository comes with a working demo project.
176176
1. Move into the directory: `cd player-loader-webpack-plugin`
177177
1. Install dependencies: `npm i`
178178
1. Set environment variables that will configure the demo. At a minimum, `BC_ACCOUNT_ID`: `export BC_ACCOUNT_ID="1234567890"` (`BC_PLAYER_ID` and `BC_EMBED_ID` are also supported).
179-
1. Run the demo: `npm run demo`
179+
1. Run the demo: `npm run start` to run the demo and a local server
180180
1. If everything succeeds, wait for the web server to start then open `http://localhost:9999/` in the browser.
181181

182182
## Options

demo/webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module.exports = {
1919
filename: 'dist.js',
2020
path: path.resolve(__dirname)
2121
},
22-
mode: 'development',
2322
plugins: [
2423
new PlayerLoader({accountId, embedId, playerId, prependTo: 'demo.js'})
2524
]

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
"repository": "github:brightcove/player-loader-webpack-plugin",
66
"main": "src/index.js",
77
"scripts": {
8-
"predemo": "rm -f ./demo/dist.js",
8+
"clean": "rm -f ./demo/dist.js",
9+
"predemo": "npm run clean",
910
"demo": "webpack --config ./demo/webpack.config.js",
10-
"postdemo": "npm run start",
1111
"docs": "npm-run-all docs:*",
1212
"docs:toc": "doctoc README.md",
1313
"test": "vjsstandard",
1414
"lint": "vjsstandard",
15-
"start": "http-server demo -p 9999",
15+
"start": "npm run demo && npm run server",
16+
"server": "http-server demo -p 9999",
1617
"update-changelog": "conventional-changelog -p videojs -i CHANGELOG.md -s",
1718
"version": "is-prerelease || npm run update-changelog && git add CHANGELOG.md",
1819
"prepublish": "not-in-install && pkg-ok || in-install"

test-webpack.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* eslint-disable no-console */
2+
const spawnSync = require('child_process').spawnSync;
3+
const spawnOptions = {};
4+
const path = require('path');
5+
const fs = require('fs');
6+
7+
let debug = false;
8+
9+
for (let i = 0; i < process.argv.length; i++) {
10+
if ((/-d|--debug/).test(process.argv[i])) {
11+
debug = true;
12+
break;
13+
}
14+
}
15+
16+
if (debug) {
17+
spawnOptions.stdio = 'inherit';
18+
}
19+
20+
const commands = [
21+
['npm', 'i', '--no-save', 'webpack@4'],
22+
['npm', 'run', 'demo'],
23+
['npm', 'run', 'clean'],
24+
['npm', 'i', '--no-save', 'webpack@3'],
25+
['npm', 'run', 'demo'],
26+
['npm', 'run', 'clean']
27+
];
28+
29+
let exitCode = 0;
30+
31+
for (let i = 0; i < commands.length; i++) {
32+
const args = commands[i];
33+
const cmd = args.shift();
34+
const command = `${path.basename(cmd)} ${args.join(' ')}`;
35+
36+
const options = Object.assign({}, spawnOptions);
37+
38+
console.log(`** Running '${command}' **`);
39+
const retval = spawnSync(cmd, args, options);
40+
41+
if (retval.status !== 0) {
42+
const output = retval.output
43+
.filter((s) => !!s)
44+
.map((s) => s.toString())
45+
.join('');
46+
47+
console.error(output);
48+
exitCode = 1;
49+
}
50+
51+
if (command === 'npm run demo') {
52+
const stat = fs.statSync(path.join(__dirname, 'demo', 'dist.js'));
53+
54+
if (stat.size < 10000) {
55+
console.error('npm run demo failed, demo/dist.js is below 10k bytes');
56+
exitCode = 1;
57+
}
58+
}
59+
60+
if (exitCode !== 0) {
61+
break;
62+
}
63+
}
64+
65+
console.log("** Running 'npm ci' to reset local deps");
66+
const retval = spawnSync('npm', ['ci'], spawnOptions);
67+
68+
if (retval.status !== 0) {
69+
console.error('Failed to reset npm deps');
70+
exitCode = 1;
71+
}
72+
73+
process.exit(exitCode);

0 commit comments

Comments
 (0)