1 | 'use strict';
|
2 |
|
3 | var shelljs = require('shelljs');
|
4 | var fs = require('fs');
|
5 | var path = require('path');
|
6 | var childProcess = require('child_process');
|
7 | var globby = require('globby');
|
8 | var fixDir = __dirname + '/../fixture';
|
9 | var tmpDir = __dirname + '/../fixture/tmp';
|
10 | var removeVariance = require('./removeVariance');
|
11 |
|
12 | shelljs.rm('-fR', tmpDir);
|
13 | shelljs.mkdir('-p', tmpDir);
|
14 | shelljs.touch(tmpDir + '/.empty');
|
15 |
|
16 | describe('Invig', function () {
|
17 | describe('cli', function () {
|
18 | test('invigorates an entire directory', function () {
|
19 | var files = globby.sync([fixDir + '/*.coffee', fixDir + '/*.js']);
|
20 | files.forEach(function (src) {
|
21 | var base = path.basename(src);
|
22 | var dst = tmpDir + '/' + base;
|
23 |
|
24 | shelljs.cp('-f', path.dirname(src) + '/package.json', path.dirname(dst) + '/package.json');
|
25 | shelljs.cp('-f', src, dst);
|
26 | var cmd = 'env SCROLEX_MODE=passthru node ' + __dirname + '/cli.js --src "' + dst + '"';
|
27 |
|
28 | var p = shelljs.exec(cmd);
|
29 | expect(removeVariance(p.stderr.trim())).toMatchSnapshot();
|
30 | expect(removeVariance(p.stdout.trim())).toMatchSnapshot();
|
31 | expect(p.code).toMatchSnapshot();
|
32 | expect(p.code).toBe(0);
|
33 |
|
34 | var result = fs.readFileSync(dst.replace(/\.coffee$/, '.js'), 'utf-8');
|
35 | expect(removeVariance(result.trim())).toMatchSnapshot();
|
36 |
|
37 | var pkg = fs.readFileSync(path.dirname(dst) + '/package.json', 'utf-8').trim();
|
38 | expect(pkg).toMatchSnapshot();
|
39 | });
|
40 | });
|
41 | test('invigorates via stdin', function (done) {
|
42 | var child = childProcess.spawn(process.argv[0], [__dirname + '/cli.js', '-qs', '-'], {
|
43 | env: {
|
44 | SCROLEX_MODE: 'passthru'
|
45 | }
|
46 | });
|
47 |
|
48 | child.stdin.write('console.log("hello")');
|
49 | child.stdin.end();
|
50 |
|
51 | var buf = '';
|
52 | child.stdout.on('data', function (data) {
|
53 | buf += '' + data;
|
54 | });
|
55 |
|
56 | child.on('close', function (code) {
|
57 | expect(removeVariance(buf)).toMatchSnapshot();
|
58 | done();
|
59 | });
|
60 | });
|
61 | });
|
62 | });
|
63 |
|
\ | No newline at end of file |