Skip to content

Commit

Permalink
Add AppVeyor CI & fix tests on Windows (#183)
Browse files Browse the repository at this point in the history
* Enable AppVeyor windows builds

* Fix css, glob, javascript, watcher, html and hmr tests on windows
  • Loading branch information
brandon93s authored and devongovett committed Dec 11, 2017
1 parent 0ff76be commit 0eb7a93
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 27 deletions.
24 changes: 24 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Test against the latest version of this Node.js version
environment:
nodejs_version: "8"

# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- yarn install

# Post-install test scripts.
test_script:
# Output useful info for debugging.
- node --version
- yarn --version
# run tests
- yarn test

cache:
- "%LOCALAPPDATA%\\Yarn"

# Don't actually build.
build: off
11 changes: 9 additions & 2 deletions src/assets/GlobAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ class GlobAsset extends Asset {
}

async load() {
let files = await globPromise(this.name, {strict: true, nodir: true});
let re = micromatch.makeRe(this.name, {capture: true});
let regularExpressionSafeName = this.name;
if (process.platform === 'win32')
regularExpressionSafeName = regularExpressionSafeName.replace(/\\/g, '/');

let files = glob.sync(regularExpressionSafeName, {
strict: true,
nodir: true
});
let re = micromatch.makeRe(regularExpressionSafeName, {capture: true});
let matches = {};

for (let file of files) {
Expand Down
8 changes: 6 additions & 2 deletions test/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,14 @@ describe('css', function() {

let output = run(b);
assert.equal(typeof output, 'function');
assert.equal(output(), '_index_1ezyc_1');

let value = output();
assert(/_index_[0-9a-z]+_1/.test(value));

let cssClass = value.match(/(_index_[0-9a-z]+_1)/)[1];

let css = fs.readFileSync(__dirname + '/dist/index.css', 'utf8');
assert(css.includes('._index_1ezyc_1'));
assert(css.includes(`.${cssClass}`));
});

it('should minify CSS in production mode', async function() {
Expand Down
12 changes: 6 additions & 6 deletions test/hmr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const assert = require('assert');
const fs = require('fs');
const {bundler, run, assertBundleTree} = require('./utils');
const path = require('path');
const {bundler, run, assertBundleTree, sleep} = require('./utils');
const rimraf = require('rimraf');
const promisify = require('../src/utils/promisify');
const ncp = promisify(require('ncp'));
Expand Down Expand Up @@ -31,10 +32,6 @@ describe('hmr', function() {
});
}

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

it('should emit an HMR update for the file that changed', async function() {
await ncp(__dirname + '/integration/commonjs', __dirname + '/input');

Expand Down Expand Up @@ -90,7 +87,10 @@ describe('hmr', function() {
assert.equal(msg.type, 'error');
assert.equal(
msg.error.message,
__dirname + '/input/local.js:1:12: Unexpected token, expected , (1:12)'
`${path.join(
__dirname,
'/input/local.js'
)}:1:12: Unexpected token, expected , (1:12)`
);
assert.equal(
msg.error.stack,
Expand Down
8 changes: 6 additions & 2 deletions test/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ describe('html', function() {
});

let html = fs.readFileSync(__dirname + '/dist/index.html');
assert(/<link rel="stylesheet" href="\/dist\/[a-f0-9]+\.css">/.test(html));
assert(
/<link rel="stylesheet" href="[\/\\]{1}dist[\/\\]{1}[a-f0-9]+\.css">/.test(
html
)
);
});

it('should insert a HEAD element if needed when adding CSS bundles', async function() {
Expand All @@ -99,7 +103,7 @@ describe('html', function() {

let html = fs.readFileSync(__dirname + '/dist/index.html');
assert(
/<head><link rel="stylesheet" href="\/dist\/[a-f0-9]+\.css"><\/head>/.test(
/<head><link rel="stylesheet" href="[\/\\]{1}dist[\/\\]{1}[a-f0-9]+\.css"><\/head>/.test(
html
)
);
Expand Down
15 changes: 9 additions & 6 deletions test/javascript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const {bundle, run, assertBundleTree} = require('./utils');

describe('javascript', function() {
Expand Down Expand Up @@ -63,10 +64,12 @@ describe('javascript', function() {
assertBundleTree(b, {
name: 'index.js',
assets: ['index.js', 'bundle-loader.js', 'bundle-url.js'],
childBundles: [{
assets: ['local.js'],
childBundles: []
}]
childBundles: [
{
assets: ['local.js'],
childBundles: []
}
]
});

let output = run(b).default;
Expand Down Expand Up @@ -156,8 +159,8 @@ describe('javascript', function() {

let output = run(b);
assert.deepEqual(output(), {
dir: __dirname + '/integration/globals',
file: __dirname + '/integration/globals/index.js',
dir: path.join(__dirname, '/integration/globals'),
file: path.join(__dirname, '/integration/globals/index.js'),
buf: new Buffer('browser').toString('base64'),
global: true
});
Expand Down
21 changes: 19 additions & 2 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,26 @@ const fs = require('fs');
const path = require('path');
const WebSocket = require('ws');

beforeEach(function() {
rimraf.sync(path.join(__dirname, 'dist'));
beforeEach(function(done) {
const finalize = () => {
rimraf.sync(path.join(__dirname, 'dist'));
done();
};

// Test run in a single process, creating and deleting the same file(s)
// Windows needs a delay for the file handles to be released before deleting
// is possible. Without a delay, rimraf fails on `beforeEach` for `/dist`
if (process.platform === 'win32') {
sleep(50).then(finalize);
} else {
finalize();
}
});

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

function bundler(file, opts) {
return new Bundler(
file,
Expand Down Expand Up @@ -107,6 +123,7 @@ function assertBundleTree(bundle, tree) {
}
}

exports.sleep = sleep;
exports.bundler = bundler;
exports.bundle = bundle;
exports.run = run;
Expand Down
11 changes: 4 additions & 7 deletions test/watcher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const assert = require('assert');
const fs = require('fs');
const {bundler, run, assertBundleTree} = require('./utils');
const path = require('path');
const {bundler, run, assertBundleTree, sleep} = require('./utils');
const rimraf = require('rimraf');
const promisify = require('../src/utils/promisify');
const ncp = promisify(require('ncp'));
Expand All @@ -23,10 +24,6 @@ describe('watcher', function() {
});
}

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

it('should rebuild on file change', async function() {
await ncp(__dirname + '/integration/commonjs', __dirname + '/input');

Expand Down Expand Up @@ -155,7 +152,7 @@ describe('watcher', function() {
let output = run(bundle);
assert.equal(await output(), 7);

assert(b.loadedAssets.has(__dirname + '/input/common-dep.js'));
assert(b.loadedAssets.has(path.join(__dirname, '/input/common-dep.js')));

// Get rid of common-dep.js
fs.writeFileSync(__dirname + '/input/common.js', 'module.exports = 5;');
Expand All @@ -179,6 +176,6 @@ describe('watcher', function() {
output = run(bundle);
assert.equal(await output(), 13);

assert(!b.loadedAssets.has(__dirname + '/input/common-dep.js'));
assert(!b.loadedAssets.has(path.join(__dirname, '/input/common-dep.js')));
});
});

0 comments on commit 0eb7a93

Please sign in to comment.