From 299bb2a2e1e16527d873155735c1adb019d0447e Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Wed, 27 Jun 2018 15:15:43 +0200 Subject: [PATCH] Make 'npm test' run on Windows --- Makefile | 3 +-- package.json | 2 +- test/run.js | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 test/run.js diff --git a/Makefile b/Makefile index 007462553..4f5fc0193 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ -TESTS = $(shell find test/test.*.js) test: - @./test/run $(TESTS) + @./test/run.js .PHONY: test \ No newline at end of file diff --git a/package.json b/package.json index de415afcb..c522c2602 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "scripts": { "lint": "eslint index.js", - "test": "make test && npm run test-typings", + "test": "node test/run.js && npm run test-typings", "test-typings": "node_modules/typescript/bin/tsc -p tsconfig.json" }, "main": "index", diff --git a/test/run.js b/test/run.js new file mode 100644 index 000000000..45ddce056 --- /dev/null +++ b/test/run.js @@ -0,0 +1,22 @@ +#!/usr/bin/env node + +const { spawnSync } = require('child_process') +const { readdirSync } = require('fs') +const { extname, join } = require('path') + +process.env.NODE_ENV = 'test'; + +process.stdout.write('\n') +readdirSync(__dirname).forEach((file) => { + if (!file.startsWith('test.') || extname(file) !== '.js') + return; + process.stdout.write(`\x1b[90m ${file}\x1b[0m `); + const result = spawnSync(process.argv0, [ join('test', file) ]); + if (result.status === 0) { + process.stdout.write('\x1b[36m✓\x1b[0m\n'); + } else { + process.stdout.write('\x1b[31m✖\x1b[0m\n'); + console.error(result.stderr.toString('utf8')); + process.exit(result.status); + } +})