1 | 'use strict';
|
2 |
|
3 | const path = require('path');
|
4 | const shell = require('shelljs');
|
5 | const expect = require('chai').expect;
|
6 |
|
7 | const pkgJsonPath = path.join(__dirname, './pkg.json');
|
8 | const ykitPath = path.join(__dirname, '../bin/ykit');
|
9 | const kill = require('../src/utils/psKill');
|
10 |
|
11 | describe('YKIT CLI', () => {
|
12 | it('installs ykit', () => {
|
13 | if (shell.test('-d', 'cli-test')) {
|
14 | shell.rm('-rf', 'cli-test');
|
15 | }
|
16 |
|
17 | shell.mkdir('cli-test');
|
18 | shell.cd('cli-test');
|
19 | shell.cp(pkgJsonPath, 'package.json');
|
20 | const output = shell.exec('npm install --registry http://registry.npm.corp.qunar.com/');
|
21 | if (output.code !== 0) {
|
22 | process.exit();
|
23 | }
|
24 |
|
25 | expect(shell.test('-f', 'package.json')).to.be.true;
|
26 | expect(shell.test('-d', 'node_modules')).to.be.true;
|
27 | })
|
28 |
|
29 | it('runs the pack command', () => {
|
30 | if (shell.test('-d', 'cli-test')) {
|
31 | shell.rm('-rf', 'cli-test');
|
32 | }
|
33 |
|
34 |
|
35 | shell.cd('cli-test');
|
36 | if (shell.exec('git clone http://gitlab.corp.qunar.com/yuhao.ju/ykit-seed-react.git').code !== 0) {
|
37 | process.exit();
|
38 | }
|
39 |
|
40 | shell.cd('ykit-seed-react');
|
41 | if (shell.exec('npm install --registry http://registry.npm.corp.qunar.com/').code !== 0) {
|
42 | process.exit();
|
43 | }
|
44 |
|
45 | if (shell.exec(ykitPath + ' pack').code !== 0) {
|
46 | process.exit();
|
47 | }
|
48 |
|
49 | expect(shell.test('-f', 'package.json')).to.be.true;
|
50 | expect(shell.test('-d', 'node_modules')).to.be.true;
|
51 | })
|
52 |
|
53 | it('runs the server command', (done) => {
|
54 | shell.cd('cli-test');
|
55 | const child = shell.exec(ykitPath + ' server -p 3000', () => {
|
56 |
|
57 | });
|
58 |
|
59 | let serverStarted = false
|
60 | child.stdout.on('data', (data) => {
|
61 | if (data.includes('Starting up server')) {
|
62 | serverStarted = true
|
63 | shell.exec('sleep 3');
|
64 |
|
65 | const output = shell.exec('curl -I localhost:3000');
|
66 | expect(output.includes('200'));
|
67 |
|
68 | kill(child.pid);
|
69 | done(0);
|
70 | } else if(!serverStarted){
|
71 | done('Server fails to start');
|
72 | }
|
73 | });
|
74 | })
|
75 |
|
76 | it('runs the lint command', () => {
|
77 | shell.cd('cli-test/ykit-seed-react');
|
78 | const output = shell.exec(ykitPath + ' lint');
|
79 | expect(output.includes('2 errors, 0 warnings'));
|
80 | })
|
81 |
|
82 | after(function() {
|
83 | if (shell.test('-d', 'cli-test')) {
|
84 | shell.rm('-rf', 'cli-test');
|
85 | }
|
86 | });
|
87 | })
|