Skip to content

Commit

Permalink
Make CLI tests run on Windows.
Browse files Browse the repository at this point in the history
(I would rather test the .cmd wrappers, but that can wait.)
Make tests run on Windows.
Make examples work on Windows
  • Loading branch information
hildjj committed Aug 2, 2021
1 parent a88d969 commit 7724a01
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 25 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ on:
jobs:
build:

runs-on: ubuntu-20.04

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
platform: [ubuntu-20.04, windows-latest]

runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"./packages/*"
],
"scripts": {
"clean": "rm -rf node_modules coverage .nyc_output packages/*/node_modules packages/*/coverage pacakges/*/.nyc_output",
"clean": "rimraf node_modules coverage .nyc_output packages/*/node_modules packages/*/coverage pacakges/*/.nyc_output",
"docs": "jsdoc -c .jsdoc.conf",
"lint": "eslint . --ext cjs --ext js",
"test": "ava packages/*/test/*.ava.js",
Expand All @@ -23,7 +23,7 @@
"build": "pnpm -r build",
"coverage": "nyc -r lcov npm test",
"coverage:all": "nyc -r lcov npm run test:all",
"predeploy": "rm -rf docs/example/*",
"predeploy": "rimraf docs/example/*",
"deploy": "pnpm -r deploy"
},
"dependencies": {
Expand All @@ -43,6 +43,7 @@
"minami": "*",
"nve": "^14.0.0",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"typescript": "^4.3.5"
},
"license": "MIT"
Expand Down
8 changes: 5 additions & 3 deletions packages/browserify-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "",
"private": "true",
"scripts": {
"prebuild": "rm -rf dist; mkdir dist",
"build": "browserify --standalone cbor ../cbor/lib/cbor.js -t [ babelify ] | terser --compress -o dist/bundle-bf.js; browserify src/index.js -t [ babelify ] -o dist/index-bf.js; cp src/*.css src/*.html dist",
"deploy": "cp dist/* ../../docs/example",
"prebuild": "rimraf dist && mkdir dist",
"build": "browserify --standalone cbor ../cbor/lib/cbor.js -t [ babelify ] | terser --compress -o dist/bundle-bf.js && browserify src/index.js -t [ babelify ] -o dist/index-bf.js && copyfiles -u1 src/*.css src/*.html dist",
"deploy": "copyfiles -u1 dist/* ../../docs/example",
"predeploy": "npm run build"
},
"repository": {
Expand All @@ -22,7 +22,9 @@
"babelify": "^10.0.0",
"browserify": "^17.0.0",
"cbor-bigdecimal": "^7.0.6",
"copyfiles": "^2.4.1",
"node-inspect-extracted": "*",
"rimraf": "^3.0.2",
"terser": "^5.7.1"
}
}
5 changes: 3 additions & 2 deletions packages/cbor-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"man": "man"
},
"scripts": {
"clean": "rm -rf coverage .nyc_output/ man/*",
"clean": "rimraf coverage .nyc_output/ man/*",
"lint": "eslint lib/*.js bin/* test/*.js",
"test": "ava",
"man": "mkdir -p man; for f in man_src/*.md; do b=`basename $f`; marked-man $f -o man/${b%.md}.1; gzip -9f man/${b%.md}.1; done",
Expand All @@ -45,7 +45,8 @@
"marked-man": "^0.7.0",
"mock-stdio": "^1.0.3",
"nofilter": "^3.0.2",
"p-event": "^4.2.0"
"p-event": "^4.2.0",
"rimraf": "^3.0.2"
},
"license": "MIT",
"readmeFilename": "README.md",
Expand Down
8 changes: 7 additions & 1 deletion packages/cbor-cli/test/exec.ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const test = require('ava')
const { spawn } = require('child_process')
const path = require('path')
const process = require('process')
const pkg = require('../package.json')
const { Buffer } = require('buffer') // not the mangled version

Expand All @@ -19,7 +20,12 @@ function exec(bin, opts = {}) {
...process.env,
...opts.env
}
const c = spawn(bin, opts.args, {
const args = opts.args || []
if (process.platform === 'win32') {
args.unshift(bin)
;[bin] = process.argv
}
const c = spawn(bin, args, {
stdio: 'pipe',
env
})
Expand Down
5 changes: 3 additions & 2 deletions packages/cbor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"fs": false
},
"scripts": {
"clean": "rm -rf coverage .nyc_output/ docs",
"clean": "rimraf coverage .nyc_output/ docs",
"lint": "eslint lib/*.js test/*.js",
"coverage": "nyc -r lcov npm test",
"test": "ava test/*.ava.js",
Expand Down Expand Up @@ -49,7 +49,8 @@
"@types/node": "*",
"bignumber.js": "^9.0.1",
"garbage": "~0.0.0",
"p-event": "^4.2.0"
"p-event": "^4.2.0",
"rimraf": "^3.0.2"
},
"license": "MIT",
"readmeFilename": "README.md",
Expand Down
4 changes: 2 additions & 2 deletions packages/cbor/test/test-vectors.ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use command \`git submodule update --init\` to load test-vectors`)
}

// HACK: don't lose data when JSON parsing
vecStr = vecStr.replace(/"decoded":\s*(-?\d+(\.\d+)?(e[+-]\d+)?)\n/g,
vecStr = vecStr.replace(/"decoded":\s*(-?\d+(\.\d+)?(e[+-]\d+)?)\r?\n/g,
`"decoded": {
"___TYPE___": "number",
"___VALUE___": "$1"
Expand Down Expand Up @@ -108,7 +108,7 @@ test('vectors', t => {
}

if (v.hasOwnProperty('decoded')) {
t.deepEqual(decoded, v.decoded)
t.deepEqual(decoded, v.decoded, `Hex: "${v.hex}"`)

if (v.roundtrip) {
// TODO: Don't know how to make these round-trip. See:
Expand Down
8 changes: 5 additions & 3 deletions packages/parcel-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "",
"private": true,
"scripts": {
"prebuild": "rm -rf dist",
"prebuild": "rimraf -rf dist",
"build": "parcel build src/index-p.html --dist-dir dist --no-source-maps --public-url .",
"deploy": "cp dist/* ../../docs/example",
"deploy": "copyfiles -u1 dist/* ../../docs/example",
"predeploy": "npm run build"
},
"keywords": [],
Expand All @@ -22,9 +22,11 @@
"bignumber.js": "^9.0.1",
"cbor": "^7.0.6",
"cbor-bigdecimal": "^7.0.6",
"copyfiles": "^2.4.1",
"node-inspect-extracted": "*",
"parcel": "2.0.0-beta.2",
"postcss": "^8.3.6",
"regenerator-runtime": "^0.13.9"
"regenerator-runtime": "^0.13.9",
"rimraf": "^3.0.2"
}
}
4 changes: 2 additions & 2 deletions packages/plain-demo/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ const scriptNames = {}
for (const s of scripts) {
const scriptSrc = bresolve.sync(s, { filename: __filename })
const local = path.basename(scriptSrc)
scriptNames[script] = local
scriptNames[s] = local

console.log(`Resolve: ${script} (${path.relative(__dirname, scriptSrc)})`)
console.log(`Resolve: ${s} (${path.relative(__dirname, scriptSrc)})`)
fs.copyFileSync(scriptSrc, path.join(dist, local))
}

Expand Down
3 changes: 2 additions & 1 deletion packages/plain-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "node build.js",
"predeploy": "npm run build",
"deploy": "ls dist/* | xargs -I {} cp {} ../../docs/example"
"deploy": "copyfiles -u1 dist/* ../../docs/example"
},
"author": "Joe Hildebrand <joe-github@cursive.net>",
"license": "MIT",
Expand All @@ -20,6 +20,7 @@
"browser-resolve": "^2.0.0",
"cbor-bigdecimal": "^7.0.6",
"cbor-web": "^7.0.6",
"copyfiles": "^2.4.1",
"node-inspect-extracted": "^1.0.8"
}
}
12 changes: 8 additions & 4 deletions packages/puppeteer-demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const TOP = 'file://' +
path.resolve(__dirname, '..', '..', 'docs', 'example', 'index.html')

let executablePath = process.env.PUPPETEER_EXECUTABLE_PATH
if (!executablePath) {
if (!executablePath && (process.platform === 'darwin')) {
executablePath = path.resolve(
'/',
'Applications',
Expand All @@ -20,10 +20,14 @@ if (!executablePath) {
'Google Chrome'
)
}
if (!executablePath) {
throw new Error('Set PUPPETEER_EXECUTABLE_PATH environment variable')
if (executablePath) {
try {
fs.accessSync(executablePath, fs.constants.X_OK)
} catch (ignored) {
executablePath = undefined
delete process.env.PUPPETEER_EXECUTABLE_PATH
}
}
fs.accessSync(executablePath, fs.constants.X_OK)

async function main() {
const browser = await puppeteer.launch({
Expand Down
3 changes: 2 additions & 1 deletion packages/webpack-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"scripts": {
"build": "webpack",
"deploy": "cp dist/* ../../docs/example",
"deploy": "copyfiles -u1 dist/* ../../docs/example",
"predeploy": "npm run build"
},
"keywords": [],
Expand All @@ -23,6 +23,7 @@
"buffer": "*",
"cbor-bigdecimal": "^7.0.6",
"cbor-web": "^7.0.6",
"copyfiles": "^2.4.1",
"css-loader": "^6.2.0",
"events": "^3.3.0",
"html-webpack-plugin": "^5.3.2",
Expand Down

0 comments on commit 7724a01

Please sign in to comment.