|
1 | | -var fs = require('fs') |
| 1 | +var _ = require('lodash') |
2 | 2 | var path = require('path') |
3 | | -var exec = require('child_process').exec |
4 | | -var mkdirp = require('mkdirp') |
5 | | -var rimraf = require('rimraf') |
| 3 | + |
| 4 | +var base = function (glob) { |
| 5 | + return path.resolve('test/fixtures/user-scripts/find-executables', glob) |
| 6 | +} |
| 7 | +var subject = require('./find-executables') |
6 | 8 |
|
7 | 9 | module.exports = { |
8 | 10 | beforeEach: function () { |
9 | 11 | td.replace(console, 'warn') |
10 | | - this.foo1 = path.join(__dirname, 'foo') |
11 | | - this.foo2 = path.join(__dirname, 'foo.lol') |
12 | | - this.subject = require('./find-executables') |
13 | | - }, |
14 | | - afterEach: function () { |
15 | | - [this.foo1, this.foo2].forEach(function (f) { |
16 | | - try { |
17 | | - fs.unlinkSync(f) |
18 | | - } catch (e) {} |
19 | | - }) |
20 | 12 | }, |
21 | 13 | noFilesFound: function (done) { |
22 | | - this.subject(path.resolve(__dirname, 'foo*'), function (er, result) { |
| 14 | + subject(base('does-not-exist*'), function (er, result) { |
23 | 15 | assert.deepEqual(result, []) |
24 | 16 | done(er) |
25 | 17 | }) |
26 | 18 | }, |
27 | 19 | oneFileFound: function (done) { |
28 | | - fs.writeFileSync(this.foo1, 'hi') |
29 | | - exec('chmod +x "' + this.foo1 + '"', function () { |
30 | | - this.subject(path.resolve(__dirname, 'foo*'), function (er, result) { |
31 | | - assert.deepEqual(result, [this.foo1]) |
32 | | - done(er) |
33 | | - }.bind(this)) |
34 | | - }.bind(this)) |
| 20 | + subject(base('is-executable*'), function (er, result) { |
| 21 | + assert.deepEqual(result, [base('is-executable')]) |
| 22 | + done(er) |
| 23 | + }) |
35 | 24 | }, |
36 | 25 | oneFileFoundWithOneNonExecutable: function (done) { |
37 | 26 | if (process.platform === 'win32') return done() |
38 | | - fs.writeFileSync(this.foo1, 'hi') |
39 | | - fs.writeFileSync(this.foo2, 'hi') |
40 | | - exec('chmod +x "' + this.foo1 + '"', function () { |
41 | | - this.subject(path.resolve(__dirname, 'foo*'), function (er, result) { |
42 | | - assert.deepEqual(result, [this.foo1]) |
43 | | - td.verify(console.warn( |
44 | | - 'Warning: scripty - ignoring script "' + this.foo2 + '" because it' + |
45 | | - ' was not executable. Run `chmod +x "' + this.foo2 + '" if you want' + |
46 | | - ' scripty to run it.' |
47 | | - )) |
48 | | - done(er) |
49 | | - }.bind(this)) |
50 | | - }.bind(this)) |
| 27 | + subject(base('file.*'), function (er, result) { |
| 28 | + assert.deepEqual(result, [base('file.executable')]) |
| 29 | + td.verify(console.warn( |
| 30 | + 'Warning: scripty - ignoring script "' + base('file.not.executable') + |
| 31 | + '" because it was not executable. Run `chmod +x "' + |
| 32 | + base('file.not.executable') + '" if you want scripty to run it.' |
| 33 | + )) |
| 34 | + done(er) |
| 35 | + }) |
51 | 36 | }, |
52 | 37 | twoFilesFound: function (done) { |
53 | | - fs.writeFileSync(this.foo1, 'hi') |
54 | | - fs.writeFileSync(this.foo2, 'hi') |
55 | | - |
56 | | - exec('chmod +x "' + this.foo1 + '" "' + this.foo2 + '"', function () { |
57 | | - this.subject(path.resolve(__dirname, 'foo*'), function (er, result) { |
58 | | - assert.deepEqual(result, [this.foo1, this.foo2]) |
59 | | - done(er) |
60 | | - }.bind(this)) |
61 | | - }.bind(this)) |
| 38 | + subject(base('exec.*'), function (er, result) { |
| 39 | + assert.deepEqual(_.sortBy(result), [base('exec.rb'), base('exec.sh')]) |
| 40 | + done(er) |
| 41 | + }) |
62 | 42 | }, |
63 | 43 | dirFound: function (done) { |
64 | | - mkdirp.sync(this.foo1) |
65 | | - this.subject(path.resolve(__dirname, 'foo*'), function (er, result) { |
| 44 | + subject(base('exec-dir-wat*'), function (er, result) { |
66 | 45 | assert.deepEqual(result, []) |
67 | | - rimraf.sync(this.foo1) |
68 | 46 | done(er) |
69 | | - }.bind(this)) |
| 47 | + }) |
70 | 48 | } |
71 | 49 | } |
72 | 50 |
|
73 | | -if (UNSUPPORTED_TDD) module.exports = {} |
0 commit comments