Skip to content

Commit

Permalink
fix unit test CI with Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
fritx committed Oct 20, 2022
1 parent dd2f9f8 commit ece6188
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ jobs:
strategy:
matrix:
node-version:
# currently devDependencies require node>=6
# - 6 # skip
# currently devDependencies require node>=6 (>=8 with Windows)
# - 8 # skip
# - 10 # skip
# - 12 # skip
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"devDependencies": {
"bufferhelper": "^0.2.1",
"mocha": "^2.4.5",
"nyc": "^11.6.0"
"nyc": "^11.6.0",
"which": "^2.0.2"
},
"dependencies": {
"lodash": "^4.12.0",
Expand Down
21 changes: 13 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ const assert = require('assert')
const cp = require('child_process')
const fs = require('fs')

let nodeCmd = 'node'
if (process.platform === 'win32') {
nodeCmd = require('which').sync('node')
}

// todo: more test cases

describe('jayin', () => {
it ('x', (done) => {
const helper = new BufferHelper()
const js = cp.spawn('node', ['./index.js', 'x.slice(2, 4)'])
const js = cp.spawn(nodeCmd, ['./index.js', 'x.slice(2, 4)'])
js.stdout.once('end', () => {
assert.equal(helper.toString(), '[3,4]')
done()
Expand All @@ -23,7 +28,7 @@ describe('jayin', () => {

it('-t', (done) => {
const helper = new BufferHelper()
const js = cp.spawn('node', ['./index.js', '-t', 'x.slice(1, -1).replace(/,/g, `\n`)'])
const js = cp.spawn(nodeCmd, ['./index.js', '-t', 'x.slice(1, -1).replace(/,/g, `\n`)'])
js.stdout.once('end', () => {
assert.equal(helper.toString(), '1\n2\n3\n4\n5')
done()
Expand All @@ -36,7 +41,7 @@ describe('jayin', () => {

it('-ti', (done) => {
const helper = new BufferHelper()
const js = cp.spawn('node', ['./index.js', '-ti', 'a=JSON.parse(x), a.push(999), a'])
const js = cp.spawn(nodeCmd, ['./index.js', '-ti', 'a=JSON.parse(x), a.push(999), a'])
js.stdout.once('end', () => {
assert.equal(helper.toString(), '[1,2,3,4,5,999]')
done()
Expand All @@ -49,7 +54,7 @@ describe('jayin', () => {

it('-to', (done) => {
const helper = new BufferHelper()
const js = cp.spawn('node', ['./index.js', '-to', 'x.join(`\n`)'])
const js = cp.spawn(nodeCmd, ['./index.js', '-to', 'x.join(`\n`)'])
js.stdout.once('end', () => {
assert.equal(helper.toString(), '1\n2\n3\n4\n5')
done()
Expand All @@ -62,7 +67,7 @@ describe('jayin', () => {

it('exprs', (done) => {
const helper = new BufferHelper()
const js = cp.spawn('node', ['./index.js', 'x.filter(x => x % 2)', 'x.reverse()'])
const js = cp.spawn(nodeCmd, ['./index.js', 'x.filter(x => x % 2)', 'x.reverse()'])
js.stdout.once('end', () => {
assert.equal(helper.toString(), '[3,1]')
done()
Expand All @@ -75,7 +80,7 @@ describe('jayin', () => {

it('no expr', (done) => {
const helper = new BufferHelper()
const js = cp.spawn('node', ['./index.js'])
const js = cp.spawn(nodeCmd, ['./index.js'])
js.stdout.once('end', () => {
assert.equal(helper.toString(), '[1,2,3,4]')
done()
Expand All @@ -88,7 +93,7 @@ describe('jayin', () => {

it('_, _.filter, _.reverse', (done) => {
const helper = new BufferHelper()
const js = cp.spawn('node', ['./index.js', '_(x).filter(x => x % 2).reverse().value()'])
const js = cp.spawn(nodeCmd, ['./index.js', '_(x).filter(x => x % 2).reverse().value()'])
js.stdout.once('end', () => {
assert.equal(helper.toString(), '[3,1]')
done()
Expand All @@ -104,7 +109,7 @@ describe('jayin', () => {
// const env = { count: 0 }
// execSync('count=0')
const helper = new BufferHelper()
const js = cp.spawn('node', ['./index.js', '-e', '-c', 'echo "${i}: ${x}" >> tmp'])
const js = cp.spawn(nodeCmd, ['./index.js', '-e', '-c', 'echo "${i}: ${x}" >> tmp'])
js.stdout.once('end', () => {
// assert.equal(execSync('echo $count').toString(), '15')
// assert.equal(env.count, '15')
Expand Down

0 comments on commit ece6188

Please sign in to comment.