|
1 | 1 | describe('shep.build', () => {
|
2 |
| - const exec = td.replace('../src/util/modules/exec') |
3 |
| - td.when(exec(), { ignoreExtraArgs: true }).thenResolve() |
4 |
| - |
5 | 2 | it('Executes custom command', async () => {
|
6 | 3 | const buildCommand = 'custom-build --cool-flag -x 6'
|
7 |
| - const load = td.replace('../src/util/load') |
8 |
| - td.when(load.pkg()).thenResolve({ shep: { buildCommand } }) |
9 |
| - td.when(exec(), { ignoreExtraArgs: true }).thenResolve() |
10 |
| - const shep = require('../src') |
| 4 | + const exec = async (command) => { |
| 5 | + assert.equal(command, buildCommand) |
| 6 | + } |
| 7 | + exec['@global'] = true |
| 8 | + const shep = proxyquire('../src/', { |
| 9 | + './load': { |
| 10 | + '@global': true, |
| 11 | + pkg: async () => { return { shep: { buildCommand } } } |
| 12 | + }, |
| 13 | + './modules/exec': exec |
| 14 | + }) |
11 | 15 |
|
12 |
| - td.when(exec(buildCommand), { ignoreExtraArgs: true }).thenResolve() |
13 | 16 | await shep.build({ quiet: true })
|
14 | 17 | })
|
15 | 18 |
|
16 | 19 | it('Logs to console when no webpack found', async () => {
|
17 |
| - let error = new Error() |
| 20 | + const error = new Error() |
18 | 21 | error.code = 'ENOENT'
|
19 | 22 |
|
20 |
| - const load = td.replace('../src/util/load') |
21 |
| - td.when(load.pkg()).thenResolve({ shep: {} }) |
| 23 | + const exec = async (command) => { |
| 24 | + throw error |
| 25 | + } |
| 26 | + exec['@global'] = true |
22 | 27 |
|
23 |
| - td.when(exec('webpack --bail'), { ignoreExtraArgs: true }).thenReject(error) |
24 |
| - td.replace(console, 'warn') |
| 28 | + const shep = proxyquire('../src/', { |
| 29 | + './load': { |
| 30 | + '@global': true, |
| 31 | + pkg: async () => { return { shep: { } } } |
| 32 | + }, |
| 33 | + './modules/exec': exec |
| 34 | + }) |
25 | 35 |
|
26 |
| - const shep = require('../src') |
27 |
| - error = await assert.isRejected(shep.build({ quiet: true })) |
28 |
| - assert.equal(error.code, 'ENOENT') |
29 |
| - td.verify(console.warn(), { ignoreExtraArgs: true }) |
| 36 | + assert.deepEqual(await assert.isRejected(shep.build({ quiet: true })), error) |
30 | 37 | })
|
31 | 38 |
|
32 |
| - describe('Executed webpack', async () => { |
33 |
| - const load = td.replace('../src/util/load') |
34 |
| - const shep = require('../src') |
35 |
| - td.when(load.pkg()).thenResolve({}) |
36 |
| - td.when(exec('webpack --bail'), { ignoreExtraArgs: true }).thenResolve() |
| 39 | + it('Executed webpack', async () => { |
| 40 | + const exec = async (command) => { |
| 41 | + assert.equal(command, 'webpack --bail') |
| 42 | + } |
| 43 | + exec['@global'] = true |
| 44 | + |
| 45 | + const shep = proxyquire('../src/', { |
| 46 | + './load': { |
| 47 | + '@global': true, |
| 48 | + pkg: async () => { return { shep: { } } } |
| 49 | + }, |
| 50 | + './modules/exec': exec |
| 51 | + }) |
37 | 52 | await shep.build({ quiet: true })
|
38 | 53 | })
|
39 | 54 | })
|
0 commit comments