Skip to content

Commit 9a6bdb1

Browse files
sylvainpolletvillardRyanZim
authored andcommitted
Fix tests on Windows (postcss#196)
1 parent 97627f5 commit 9a6bdb1

File tree

6 files changed

+28
-34
lines changed

6 files changed

+28
-34
lines changed

test/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test('--base --dir works', async t => {
99
const dir = tmp()
1010

1111
const { error, stderr } = await cli([
12-
'test/fixtures/base/**/*.css',
12+
'"test/fixtures/base/**/*.css"',
1313
'--dir',
1414
dir,
1515
'--base',

test/helpers/cli.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import path from 'path'
2-
import { execFile } from 'child_process'
2+
import { exec } from 'child_process'
33

44
export default function(args, cwd) {
55
return new Promise(resolve => {
6-
execFile(
7-
path.resolve('bin/postcss'),
8-
args,
6+
exec(
7+
`node ${path.resolve('bin/postcss')} ${args.join(' ')}`,
98
{ cwd },
109
(err, stdout, stderr) => {
1110
resolve({

test/helpers/read.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { readFile } from 'fs-extra'
22

33
export default function(path) {
4-
return readFile(path, 'utf8')
4+
return readFile(path, 'utf8').then(content => content.replace(/\r\n/g, '\n')) // normalize line endings on Windows
55
}

test/stdin.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ import test from 'ava'
22

33
import fs from 'fs-extra'
44
import path from 'path'
5-
import { execFile } from 'child_process'
5+
import { exec } from 'child_process'
66

77
import tmp from './helpers/tmp.js'
88
import read from './helpers/read.js'
99

1010
test.cb('reads from stdin', t => {
1111
const output = tmp('output.css')
1212

13-
const cp = execFile(
14-
path.resolve('bin/postcss'),
15-
['-o', output, '--no-map'],
13+
const cp = exec(
14+
`node ${path.resolve('bin/postcss')} -o ${output} --no-map`,
1615
(error, stdout, stderr) => {
1716
if (error) t.end(error, stderr)
1817

test/stdout.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import test from 'ava'
22

33
import fs from 'fs-extra'
44
import path from 'path'
5-
import { execFile } from 'child_process'
5+
import { exec } from 'child_process'
66

77
import read from './helpers/read.js'
88

99
test.cb('writes to stdout', t => {
10-
const cp = execFile(
11-
path.resolve('bin/postcss'),
12-
['--parser', 'sugarss', '-u', 'postcss-import', '--no-map'],
10+
const cp = exec(
11+
`node ${path.resolve(
12+
'bin/postcss'
13+
)} --parser sugarss -u postcss-import --no-map`,
1314
(error, stdout, stderr) => {
1415
if (error) t.end(error, stderr)
1516

16-
Promise.all([stdout, read('test/fixtures/s.css')])
17+
Promise.all([stdout.replace(/\r\n/g, '\n'), read('test/fixtures/s.css')])
1718
.then(([a, e]) => {
1819
t.is(a, e)
1920
t.end()

test/watch.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import test from 'ava'
22

33
import fs from 'fs-extra'
44
import path from 'path'
5-
import { exec, execFile } from 'child_process'
5+
import { exec } from 'child_process'
66
import chokidar from 'chokidar'
77

88
import ENV from './helpers/env.js'
@@ -48,7 +48,9 @@ test.cb.skip('--watch works', t => {
4848
watcher.on('ready', () => {
4949
// Using exec() and quoting "*.css" to test watch's glob handling:
5050
cp = exec(
51-
`${path.resolve('bin/postcss')} "*.css" -o output.css --no-map -w`,
51+
`node ${path.resolve(
52+
'bin/postcss'
53+
)} "*.css" -o output.css --no-map -w`,
5254
{ cwd: dir }
5355
)
5456
cp.on('error', t.end)
@@ -124,9 +126,10 @@ test.cb.skip('--watch postcss.config.js', t => {
124126

125127
// Start postcss-cli:
126128
watcher.on('ready', () => {
127-
cp = execFile(
128-
path.resolve('bin/postcss'),
129-
['import.css', '-o', 'output.css', '-w', '--no-map'],
129+
cp = exec(
130+
`node ${path.resolve(
131+
'bin/postcss'
132+
)} import.css -o output.css -w --no-map`,
130133
{ cwd: dir }
131134
)
132135

@@ -193,17 +196,10 @@ test.cb.skip('--watch dependencies', t => {
193196

194197
// Start postcss-cli:
195198
watcher.on('ready', () => {
196-
cp = execFile(
197-
path.resolve('bin/postcss'),
198-
[
199-
'import.css',
200-
'-o',
201-
'output.css',
202-
'-u',
203-
'postcss-import',
204-
'-w',
205-
'--no-map'
206-
],
199+
cp = exec(
200+
`node ${path.resolve(
201+
'bin/postcss'
202+
)} import.css -o output.css -u postcss-import -w --no-map`,
207203
{ cwd: dir }
208204
)
209205

@@ -252,9 +248,8 @@ test.cb.skip("--watch doesn't exit on CssSyntaxError", t => {
252248
})
253249

254250
let killed = false
255-
const cp = execFile(
256-
path.resolve('bin/postcss'),
257-
['a.css', '-o', 'output.css', '-w', '--no-map'],
251+
const cp = exec(
252+
`node ${path.resolve('bin/postcss')} a.css -o output.css -w --no-map`,
258253
{ cwd: dir }
259254
)
260255
cp.on('error', t.end)

0 commit comments

Comments
 (0)