Skip to content

Commit

Permalink
Create and remove directory programmatically
Browse files Browse the repository at this point in the history
Windows PowerShell doesn’t support `&&` operator.
  • Loading branch information
shinnn committed Oct 22, 2014
1 parent 34230cc commit 481046c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ install:
build: off

test_script:
- ps: 'npm test # PowerShell'
- cmd: npm test
- ps: 'node test\test.js # PowerShell'
- cmd: node test\test.js
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"scripts": {
"postinstall": "node lib/install.js",
"test": "mkdir test/tmp && node test/test.js && rm -rf test/tmp"
"test": "node test/test.js"
},
"files": [
"cli.js",
Expand All @@ -40,6 +40,8 @@
"devDependencies": {
"ava": "^0.0.4",
"bin-check": "^1.0.0",
"compare-size": "^1.0.1"
"compare-size": "^1.0.1",
"mkdirp": "^0.5.0",
"rimraf": "^2.2.8"
}
}
18 changes: 14 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
var binCheck = require('bin-check');
var compareSize = require('compare-size');
var execFile = require('child_process').execFile;
var mkdir = require('mkdirp');
var path = require('path');
var rm = require('rimraf');
var test = require('ava');
var tmp = path.join(__dirname, 'tmp');

Expand All @@ -17,7 +19,7 @@ test('return path to binary and verify that it is working', function (t) {
});

test('minify a JPG', function (t) {
t.plan(3);
t.plan(5);

var src = path.join(__dirname, 'fixtures/test.jpg');
var dest = path.join(tmp, 'test.jpg');
Expand All @@ -28,12 +30,20 @@ test('minify a JPG', function (t) {
dest
];

execFile(require('../').path, args, function (err) {
mkdir(tmp, function (err) {
t.assert(!err, err);

compareSize(src, dest, function (err, res) {
execFile(require('../').path, args, function (err) {
t.assert(!err, err);
t.assert(res[dest] < res[src]);

compareSize(src, dest, function (err, res) {
t.assert(!err, err);
t.assert(res[dest] < res[src]);

rm(tmp, function (err) {
t.assert(!err, err);
});
});
});
});
});

2 comments on commit 481046c

@shinnn
Copy link
Contributor Author

@shinnn shinnn commented on 481046c Oct 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevva
Copy link
Contributor

@kevva kevva commented on 481046c Oct 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works here because we aren't building anything. But due to each-async (used by ava) running stuff concurrently it can sometimes remove the tmp directory since a test has successfully passed while the build test is still going on and thus making that fail.

I rather keep stuff consistent for now (using mkdir && rm -rf) until ava has support for before and after,

Please sign in to comment.