|
| 1 | +const func = require('../../../../../../../lib/cli-command.js').func; |
| 2 | + |
| 3 | +// special compact mocks for this test: |
| 4 | +const mysnap = []; |
| 5 | +const mockpushit = x => mysnap.push(x); |
| 6 | +jest.mock('fs-extra', () => ({ |
| 7 | + ensureDir: (dir) => { |
| 8 | + mockpushit({ ensureDir: dir }); |
| 9 | + return Promise.reject(new Error(`ENOPERM not permitted`)); |
| 10 | + }, |
| 11 | + outputFile: (outputFileName, theContent) => { |
| 12 | + // NOT EXPECTED: |
| 13 | + mockpushit({ outputFileName, theContent }); |
| 14 | + return Promise.reject(new Error(`ENOPERM not permitted`)); |
| 15 | + }, |
| 16 | +})); |
| 17 | + |
| 18 | +// TBD hackish mock: |
| 19 | +global.console = { |
| 20 | + info: (...args) => { |
| 21 | + mockpushit({ info: [].concat(args) }); |
| 22 | + }, |
| 23 | + log: (...args) => { |
| 24 | + mockpushit({ |
| 25 | + // TBD EXTRA WORKAROUND HACK for non-deterministic elapsed time in log |
| 26 | + log: args.map(line => line.replace(/It took.*s/g, 'It took XXX')) |
| 27 | + }); |
| 28 | + }, |
| 29 | + warn: (...args) => { |
| 30 | + mockpushit({ warn: [].concat(args) }); |
| 31 | + }, |
| 32 | + error: (first, ...rest) => { |
| 33 | + mockpushit({ |
| 34 | + error: [].concat( |
| 35 | + [].concat( |
| 36 | + first |
| 37 | + // Check trace with relative path |
| 38 | + // THANKS for guidance: |
| 39 | + // * https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string/1145525#1145525 |
| 40 | + // * https://github.com/tunnckoCore/clean-stacktrace-relative-paths/blob/v1.0.4/index.js#L59 |
| 41 | + .split(process.cwd()).join('...') |
| 42 | + // IGNORE test-dependant trace info |
| 43 | + .split(/at.*JestTest/)[0] |
| 44 | + // IGNORE line number in cli-command.js |
| 45 | + // in order to avoid sensitivity to mutation testing |
| 46 | + // (miss potentially surviving mutants) |
| 47 | + .replace(/cli-command.js:.*/, 'cli-command.js:...') |
| 48 | + // WORKAROUND for Windows: |
| 49 | + .replace(/\\/g, '/') |
| 50 | + ), |
| 51 | + rest |
| 52 | + ) |
| 53 | + }); |
| 54 | + }, |
| 55 | +}; |
| 56 | + |
| 57 | +test('create alice-bobbi module with logging, with fs error (with defaults for Android & iOS)', async () => { |
| 58 | + const args = ['alice-bobbi']; |
| 59 | + |
| 60 | + const config = 'bogus'; |
| 61 | + |
| 62 | + await func(args, config, {}); |
| 63 | + |
| 64 | + expect(mysnap).toMatchSnapshot(); |
| 65 | +}); |
0 commit comments