Skip to content

Commit

Permalink
add test for directory missing
Browse files Browse the repository at this point in the history
Check that wait-on will handle situation where directory
is missing for resource.
  • Loading branch information
jeffbski committed Jan 8, 2020
1 parent 4924915 commit 42ca4d7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"expect-legacy": "^1.20.2",
"mkdirp": "^0.5.1",
"mocha": "^6.2.2",
"temp": "^0.9.1"
},
Expand Down
29 changes: 16 additions & 13 deletions test/api.mocha.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
'use strict';

var waitOn = require('../');
var fs = require('fs');
var http = require('http');
var path = require('path');
var temp = require('temp');

var mocha = require('mocha');
var describe = mocha.describe;
var it = mocha.it;
var afterEach = mocha.afterEach;
var expect = require('expect-legacy');
const waitOn = require('../');
const fs = require('fs');
const http = require('http');
const path = require('path');
const temp = require('temp');
const mkdirp = require('mkdirp');

const mocha = require('mocha');
const describe = mocha.describe;
const it = mocha.it;
const afterEach = mocha.afterEach;
const expect = require('expect-legacy');

temp.track(); // cleanup files on exit

Expand All @@ -30,9 +31,10 @@ describe('api', function() {
temp.mkdir({}, function(err, dirPath) {
if (err) return done(err);
var opts = {
resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')]
resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar/deeper/deep/yet')]
};
fs.writeFileSync(opts.resources[0], 'data1');
mkdirp.sync(path.dirname(opts.resources[1]));
fs.writeFileSync(opts.resources[1], 'data2');
waitOn(opts, function(err) {
expect(err).toNotExist();
Expand All @@ -45,11 +47,12 @@ describe('api', function() {
temp.mkdir({}, function(err, dirPath) {
if (err) return done(err);
var opts = {
resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')]
resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar/deeper/deep/yet')]
};

setTimeout(function() {
fs.writeFile(opts.resources[0], 'data1', function() {});
mkdirp.sync(path.dirname(opts.resources[1]));
fs.writeFile(opts.resources[1], 'data2', function() {});
}, 300);

Expand Down
29 changes: 16 additions & 13 deletions test/cli.mocha.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use strict';

var childProcess = require('child_process');
var fs = require('fs');
var http = require('http');
var path = require('path');
var temp = require('temp');
const childProcess = require('child_process');
const fs = require('fs');
const http = require('http');
const path = require('path');
const temp = require('temp');
const mkdirp = require('mkdirp');

var mocha = require('mocha');
var describe = mocha.describe;
var it = mocha.it;
var afterEach = mocha.afterEach;
var expect = require('expect-legacy');
const mocha = require('mocha');
const describe = mocha.describe;
const it = mocha.it;
const afterEach = mocha.afterEach;
const expect = require('expect-legacy');

var CLI_PATH = path.resolve(__dirname, '../bin/wait-on');
const CLI_PATH = path.resolve(__dirname, '../bin/wait-on');

temp.track(); // cleanup files on exit

Expand All @@ -39,9 +40,10 @@ describe('cli', function() {
temp.mkdir({}, function(err, dirPath) {
if (err) return done(err);
var opts = {
resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')]
resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar/deeper/deep/yet')]
};
fs.writeFileSync(opts.resources[0], 'data1');
mkdirp.sync(path.dirname(opts.resources[1]));
fs.writeFileSync(opts.resources[1], 'data2');

execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) {
Expand All @@ -55,11 +57,12 @@ describe('cli', function() {
temp.mkdir({}, function(err, dirPath) {
if (err) return done(err);
var opts = {
resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')]
resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar/deeper/deep/yet')]
};

setTimeout(function() {
fs.writeFile(opts.resources[0], 'data1', function() {});
mkdirp.sync(path.dirname(opts.resources[1]));
fs.writeFile(opts.resources[1], 'data2', function() {});
}, 300);

Expand Down

0 comments on commit 42ca4d7

Please sign in to comment.