Skip to content

Commit 972ef63

Browse files
authored
Fix tests on Windows
Closes GH-21.
1 parent 3ef82d6 commit 972ef63

File tree

4 files changed

+49
-22
lines changed

4 files changed

+49
-22
lines changed

.travis.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ os:
55
node_js:
66
- lts/dubnium
77
- node
8-
after_script: bash <(curl -s https://codecov.io/bash)
8+
script:
9+
- if [ "$TRAVIS_OS_NAME" != "windows" ]; then npm test; fi
10+
- if [ "$TRAVIS_OS_NAME" = "windows" ]; then npm run test-api; fi
11+
after_script:
12+
- bash <(curl -s https://codecov.io/bash)

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"devDependencies": {
3434
"bail": "^1.0.0",
3535
"execa": "^1.0.0",
36+
"figures": "^3.0.0",
3637
"nyc": "^14.0.0",
3738
"prettier": "^1.0.0",
3839
"remark-cli": "^6.0.0",

readme.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ The watch is stopped when `SIGINT` is received (usually done by pressing
371371

372372
If [`--output`][output] is given **without** `path` it is not honoured, to
373373
prevent an infinite loop.
374-
When the watch closes, a final process runs including `--output`.
374+
On operating systems other than Windows, when the watch closes, a final process
375+
runs including `--output`.
375376

376377
* **Default**: off
377378
* **Alias**: `-w`

test/index.js

+41-20
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ var bail = require('bail')
77
var test = require('tape')
88
var touch = require('touch')
99
var strip = require('strip-ansi')
10+
var figures = require('figures')
1011

1112
var join = path.join
1213
var read = fs.readFileSync
1314
var rm = fs.unlinkSync
15+
var sep = path.sep
1416

1517
var fixtures = join(__dirname, 'fixtures')
1618

@@ -31,7 +33,7 @@ test('unified-args', function(t) {
3133
'missing.txt',
3234
' 1:1 error No such file or directory',
3335
'',
34-
'✖ 1 error',
36+
figures.cross + ' 1 error',
3537
''
3638
].join('\n')
3739

@@ -61,8 +63,8 @@ test('unified-args', function(t) {
6163
t.test('should accept a path to a directory', function(st) {
6264
var expected = [
6365
'one.txt: no issues found',
64-
'three/five.txt: no issues found',
65-
'three/four.txt: no issues found',
66+
'three' + sep + 'five.txt: no issues found',
67+
'three' + sep + 'four.txt: no issues found',
6668
'two.txt: no issues found'
6769
].join('\n')
6870

@@ -100,8 +102,8 @@ test('unified-args', function(t) {
100102

101103
t.test('should accept a glob to a directory', function(st) {
102104
var expected = [
103-
'three/five.txt: no issues found',
104-
'three/four.txt: no issues found'
105+
'three' + sep + 'five.txt: no issues found',
106+
'three' + sep + 'four.txt: no issues found'
105107
].join('\n')
106108

107109
st.plan(1)
@@ -118,7 +120,7 @@ test('unified-args', function(t) {
118120
})
119121

120122
t.test('should fail on a bad short flag', function(st) {
121-
var expected = read(join(cwd, 'SHORT_FLAG'), 'utf8')
123+
var expected = read(join(cwd, 'SHORT_FLAG'), 'utf8').replace(/\r/g, '')
122124

123125
st.plan(1)
124126

@@ -130,7 +132,7 @@ test('unified-args', function(t) {
130132
})
131133

132134
t.test('should fail on a bad grouped short flag', function(st) {
133-
var expected = read(join(cwd, 'SHORT_FLAG'), 'utf8')
135+
var expected = read(join(cwd, 'SHORT_FLAG'), 'utf8').replace(/\r/g, '')
134136

135137
st.plan(1)
136138

@@ -142,7 +144,7 @@ test('unified-args', function(t) {
142144
})
143145

144146
t.test('should fail on a bad long flag', function(st) {
145-
var expected = read(join(cwd, 'LONG_FLAG'), 'utf8')
147+
var expected = read(join(cwd, 'LONG_FLAG'), 'utf8').replace(/\r/g, '')
146148

147149
st.plan(1)
148150

@@ -155,7 +157,9 @@ test('unified-args', function(t) {
155157

156158
helpFlags.forEach(function(flag) {
157159
t.test('should show help on `' + flag + '`', function(st) {
158-
var expected = read(join(cwd, 'HELP'), 'utf8').trim()
160+
var expected = read(join(cwd, 'HELP'), 'utf8')
161+
.replace(/\r/g, '')
162+
.trim()
159163

160164
st.plan(1)
161165

@@ -209,8 +213,8 @@ test('unified-args', function(t) {
209213
var expected = [
210214
'alpha.text: no issues found',
211215
'bravo.text: no issues found',
212-
'charlie/delta.text: no issues found',
213-
'charlie/echo.text: no issues found'
216+
'charlie' + sep + 'delta.text: no issues found',
217+
'charlie' + sep + 'echo.text: no issues found'
214218
].join('\n')
215219

216220
st.plan(1)
@@ -243,8 +247,8 @@ test('unified-args', function(t) {
243247
var expected = [
244248
'alpha.text: no issues found',
245249
'bravo.text: no issues found',
246-
'charlie/delta.text: no issues found',
247-
'charlie/echo.text: no issues found'
250+
'charlie' + sep + 'delta.text: no issues found',
251+
'charlie' + sep + 'echo.text: no issues found'
248252
].join('\n')
249253

250254
st.plan(1)
@@ -448,7 +452,12 @@ test('unified-args', function(t) {
448452
touch.sync(doc)
449453

450454
proc = execa(bin, ['watch.txt', '-w'])
451-
proc.then(onsuccess, st.fail)
455+
456+
if (process.platform === 'win32') {
457+
proc.then(st.fail, onsuccess)
458+
} else {
459+
proc.then(onsuccess, st.fail)
460+
}
452461

453462
setTimeout(seeYouLaterAlligator, delay)
454463

@@ -475,14 +484,21 @@ test('unified-args', function(t) {
475484
})
476485

477486
t.test('should not regenerate when watching', function(st) {
478-
var expected = [
487+
var lines = [
479488
'Watching... (press CTRL+C to exit)',
480489
'Note: Ignoring `--output` until exit.',
481490
'watch.txt: no issues found',
482491
'watch.txt: no issues found',
483-
'',
484-
'watch.txt: written'
485-
].join('\n')
492+
''
493+
]
494+
495+
// Windows immediatly quits.
496+
// Other OSes support cleaning up things.
497+
if (process.platform !== 'win32') {
498+
lines.push('watch.txt: written')
499+
}
500+
501+
var expected = lines.join('\n')
486502
var doc = join(cwd, 'watch.txt')
487503
var resolved = false
488504
var delay = 3000
@@ -492,8 +508,13 @@ test('unified-args', function(t) {
492508

493509
touch.sync(doc)
494510

495-
proc = execa(bin, ['watch.txt', '-wo'])
496-
proc.then(onsuccess, st.fail)
511+
proc = execa(bin, ['watch.txt', '-w', '-o'])
512+
513+
if (process.platform === 'win32') {
514+
proc.then(st.fail, onsuccess)
515+
} else {
516+
proc.then(onsuccess, st.fail)
517+
}
497518

498519
setTimeout(seeYouLaterAlligator, delay)
499520

0 commit comments

Comments
 (0)