UNPKG

2.08 kBJavaScriptView Raw
1'use strict';
2
3var shelljs = require('shelljs');
4var fs = require('fs');
5var path = require('path');
6var childProcess = require('child_process');
7var globby = require('globby');
8var fixDir = __dirname + '/../fixture';
9var tmpDir = __dirname + '/../fixture/tmp';
10var removeVariance = require('./removeVariance');
11
12shelljs.rm('-fR', tmpDir);
13shelljs.mkdir('-p', tmpDir);
14shelljs.touch(tmpDir + '/.empty');
15
16describe('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 // console.log(cmd)
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//# sourceMappingURL=cli.test.js.map
\No newline at end of file