Skip to content

Commit 0eb7a93

Browse files
brandon93sdevongovett
authored andcommitted
Add AppVeyor CI & fix tests on Windows (#183)
* Enable AppVeyor windows builds * Fix css, glob, javascript, watcher, html and hmr tests on windows
1 parent 0ff76be commit 0eb7a93

8 files changed

Lines changed: 83 additions & 27 deletions

File tree

appveyor.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Test against the latest version of this Node.js version
2+
environment:
3+
nodejs_version: "8"
4+
5+
# Install scripts. (runs after repo cloning)
6+
install:
7+
# Get the latest stable version of Node.js or io.js
8+
- ps: Install-Product node $env:nodejs_version
9+
# install modules
10+
- yarn install
11+
12+
# Post-install test scripts.
13+
test_script:
14+
# Output useful info for debugging.
15+
- node --version
16+
- yarn --version
17+
# run tests
18+
- yarn test
19+
20+
cache:
21+
- "%LOCALAPPDATA%\\Yarn"
22+
23+
# Don't actually build.
24+
build: off

src/assets/GlobAsset.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ class GlobAsset extends Asset {
1212
}
1313

1414
async load() {
15-
let files = await globPromise(this.name, {strict: true, nodir: true});
16-
let re = micromatch.makeRe(this.name, {capture: true});
15+
let regularExpressionSafeName = this.name;
16+
if (process.platform === 'win32')
17+
regularExpressionSafeName = regularExpressionSafeName.replace(/\\/g, '/');
18+
19+
let files = glob.sync(regularExpressionSafeName, {
20+
strict: true,
21+
nodir: true
22+
});
23+
let re = micromatch.makeRe(regularExpressionSafeName, {capture: true});
1724
let matches = {};
1825

1926
for (let file of files) {

test/css.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,14 @@ describe('css', function() {
137137

138138
let output = run(b);
139139
assert.equal(typeof output, 'function');
140-
assert.equal(output(), '_index_1ezyc_1');
140+
141+
let value = output();
142+
assert(/_index_[0-9a-z]+_1/.test(value));
143+
144+
let cssClass = value.match(/(_index_[0-9a-z]+_1)/)[1];
141145

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

146150
it('should minify CSS in production mode', async function() {

test/hmr.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const assert = require('assert');
22
const fs = require('fs');
3-
const {bundler, run, assertBundleTree} = require('./utils');
3+
const path = require('path');
4+
const {bundler, run, assertBundleTree, sleep} = require('./utils');
45
const rimraf = require('rimraf');
56
const promisify = require('../src/utils/promisify');
67
const ncp = promisify(require('ncp'));
@@ -31,10 +32,6 @@ describe('hmr', function() {
3132
});
3233
}
3334

34-
function sleep(ms) {
35-
return new Promise(resolve => setTimeout(resolve, ms));
36-
}
37-
3835
it('should emit an HMR update for the file that changed', async function() {
3936
await ncp(__dirname + '/integration/commonjs', __dirname + '/input');
4037

@@ -90,7 +87,10 @@ describe('hmr', function() {
9087
assert.equal(msg.type, 'error');
9188
assert.equal(
9289
msg.error.message,
93-
__dirname + '/input/local.js:1:12: Unexpected token, expected , (1:12)'
90+
`${path.join(
91+
__dirname,
92+
'/input/local.js'
93+
)}:1:12: Unexpected token, expected , (1:12)`
9494
);
9595
assert.equal(
9696
msg.error.stack,

test/html.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ describe('html', function() {
7373
});
7474

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

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

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

test/javascript.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const assert = require('assert');
22
const fs = require('fs');
3+
const path = require('path');
34
const {bundle, run, assertBundleTree} = require('./utils');
45

56
describe('javascript', function() {
@@ -63,10 +64,12 @@ describe('javascript', function() {
6364
assertBundleTree(b, {
6465
name: 'index.js',
6566
assets: ['index.js', 'bundle-loader.js', 'bundle-url.js'],
66-
childBundles: [{
67-
assets: ['local.js'],
68-
childBundles: []
69-
}]
67+
childBundles: [
68+
{
69+
assets: ['local.js'],
70+
childBundles: []
71+
}
72+
]
7073
});
7174

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

157160
let output = run(b);
158161
assert.deepEqual(output(), {
159-
dir: __dirname + '/integration/globals',
160-
file: __dirname + '/integration/globals/index.js',
162+
dir: path.join(__dirname, '/integration/globals'),
163+
file: path.join(__dirname, '/integration/globals/index.js'),
161164
buf: new Buffer('browser').toString('base64'),
162165
global: true
163166
});

test/utils.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,26 @@ const fs = require('fs');
66
const path = require('path');
77
const WebSocket = require('ws');
88

9-
beforeEach(function() {
10-
rimraf.sync(path.join(__dirname, 'dist'));
9+
beforeEach(function(done) {
10+
const finalize = () => {
11+
rimraf.sync(path.join(__dirname, 'dist'));
12+
done();
13+
};
14+
15+
// Test run in a single process, creating and deleting the same file(s)
16+
// Windows needs a delay for the file handles to be released before deleting
17+
// is possible. Without a delay, rimraf fails on `beforeEach` for `/dist`
18+
if (process.platform === 'win32') {
19+
sleep(50).then(finalize);
20+
} else {
21+
finalize();
22+
}
1123
});
1224

25+
function sleep(ms) {
26+
return new Promise(resolve => setTimeout(resolve, ms));
27+
}
28+
1329
function bundler(file, opts) {
1430
return new Bundler(
1531
file,
@@ -107,6 +123,7 @@ function assertBundleTree(bundle, tree) {
107123
}
108124
}
109125

126+
exports.sleep = sleep;
110127
exports.bundler = bundler;
111128
exports.bundle = bundle;
112129
exports.run = run;

test/watcher.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const assert = require('assert');
22
const fs = require('fs');
3-
const {bundler, run, assertBundleTree} = require('./utils');
3+
const path = require('path');
4+
const {bundler, run, assertBundleTree, sleep} = require('./utils');
45
const rimraf = require('rimraf');
56
const promisify = require('../src/utils/promisify');
67
const ncp = promisify(require('ncp'));
@@ -23,10 +24,6 @@ describe('watcher', function() {
2324
});
2425
}
2526

26-
function sleep(ms) {
27-
return new Promise(resolve => setTimeout(resolve, ms));
28-
}
29-
3027
it('should rebuild on file change', async function() {
3128
await ncp(__dirname + '/integration/commonjs', __dirname + '/input');
3229

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

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

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

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

0 commit comments

Comments
 (0)