Skip to content

Commit

Permalink
Add smoke test for js users
Browse files Browse the repository at this point in the history
  • Loading branch information
kolodny committed Dec 5, 2018
1 parent 16c3ad0 commit e08bbaf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"prepretest": "rimraf ./coverage ./.nyc_output",
"pretest": "tsc -p tsconfig.test.json",
"test": "nyc ts-mocha ./test/test.js",
"pretest-js": "rimraf ./test-js-dir",
"test-js": "node test-js",
"posttest-js": "rimraf ./test-js-dir",
"posttest": "rimraf ./test",
"prepublishOnly": "npm run lint && npm run build"
},
Expand Down
28 changes: 28 additions & 0 deletions test-js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const promisify = require('util').promisify;
const fs = require('fs');
const exec = promisify(require('child_process').exec);
const mkdir = promisify(fs.mkdir);
const writeFile = promisify(fs.writeFile);
const assert = require('assert');

const code = `
const update = require('immutability-helper');
const state1 = ['x'];
const state2 = update(state1, {$push: ['y']})
console.log(JSON.stringify(state2));
`

Promise.resolve()
.then(() => mkdir('test-js-dir'))
.then(() => process.chdir('test-js-dir'))
.then(() => exec('npm init -y'))
.then(() => exec('npm install ../'))
.then(() => writeFile('foo.js', code))
.then(() => exec('node foo'))
.then(result => assert.strictEqual(result.stdout.trim(), '["x","y"]'))
.then(() => process.exit(0))
.catch(error => {
console.error('uncaught error', error);
process.exit(1);
});

0 comments on commit e08bbaf

Please sign in to comment.