|
1 |
| -var test = require('ava'); |
2 |
| -var execa = require('execa'); |
| 1 | +const test = require('ava'); |
| 2 | +const execa = require('execa'); |
| 3 | +const tempWrite = require('temp-write'); |
| 4 | +const pathExists = require('path-exists'); |
| 5 | +const path = require('path'); |
| 6 | +const readPkg = require('read-pkg'); |
| 7 | +const readFile = require('fs').readFile; |
3 | 8 |
|
4 |
| -test('Missing required arguments', t => { |
5 |
| - t.throws(execa('../cli.js')); |
| 9 | +test('Missing required arguments -i, -o', t => { |
| 10 | + t.throws(execa('../cli.js', [])); |
| 11 | +}); |
| 12 | + |
| 13 | +test('Missing required arguments -o', t => { |
| 14 | + t.throws(execa('../cli.js', ['-i', 'fixtures/input.html'])); |
| 15 | +}); |
| 16 | + |
| 17 | +test('Missing required arguments -i', t => { |
| 18 | + const filename = tempWrite.sync('output.html'); |
| 19 | + t.throws(execa('../cli.js', [`-o ${filename}`])); |
| 20 | +}); |
| 21 | + |
| 22 | +test('Check version', async t => { |
| 23 | + t.is((await execa('../cli.js', ['-v'])).stdout, (await readPkg(path.dirname(__dirname))).version); |
| 24 | +}); |
| 25 | + |
| 26 | +test('Transform html witch config in package.json', async t => { |
| 27 | + t.plan(2); |
| 28 | + function read(path) { |
| 29 | + return new Promise((resolve, reject) => { |
| 30 | + readFile(path, 'utf8', (err, data) => { |
| 31 | + if (err) { |
| 32 | + reject(err); |
| 33 | + } |
| 34 | + return resolve(data); |
| 35 | + }); |
| 36 | + }); |
| 37 | + } |
| 38 | + const filename = await tempWrite('output.html'); |
| 39 | + await execa('../cli.js', ['-i', 'fixtures/input.html', '-o', filename]); |
| 40 | + t.true(await pathExists(filename)); |
| 41 | + t.is((await read('expected/output-config-pkg.html')), (await read(filename))); |
| 42 | +}); |
| 43 | + |
| 44 | +test('Transform html witch config in file', async t => { |
| 45 | + t.plan(2); |
| 46 | + function read(path) { |
| 47 | + return new Promise((resolve, reject) => { |
| 48 | + readFile(path, 'utf8', (err, data) => { |
| 49 | + if (err) { |
| 50 | + reject(err); |
| 51 | + } |
| 52 | + return resolve(data); |
| 53 | + }); |
| 54 | + }); |
| 55 | + } |
| 56 | + const filename = await tempWrite('output.html'); |
| 57 | + await execa('../cli.js', ['-i', 'fixtures/input.html', '-o', filename, '-c', 'fixtures/config.json']); |
| 58 | + t.true(await pathExists(filename)); |
| 59 | + t.is((await read('expected/output-config-file.html')), (await read(filename))); |
6 | 60 | });
|
0 commit comments