|
1 |
| -const { spawnSync } = require('child_process') |
2 |
| -const path = require('path') |
3 |
| -const rimraf = require('rimraf') |
| 1 | +const {spawnSync} = require('child_process'); |
| 2 | +const path = require('path'); |
| 3 | +const rimraf = require('rimraf'); |
4 | 4 |
|
5 |
| -const scriptPath = path.resolve(__dirname, '../index.js') |
6 |
| -const packagePath = path.resolve(__dirname, '../__fixtures__/package') |
7 |
| -const emptyPackagePath = path.resolve(__dirname, '../__fixtures__/emptyPackage') |
| 5 | +const scriptPath = path.resolve(__dirname, '../index.js'); |
| 6 | +const packagePath = path.resolve(__dirname, '../__fixtures__/package'); |
| 7 | +const fixturesPath = path.resolve(__dirname, '../__fixtures__'); |
8 | 8 |
|
9 |
| -require('./to-run-successfully-matcher') |
| 9 | +require('./to-run-successfully-matcher'); |
10 | 10 |
|
11 | 11 | describe('[CLI] init', () => {
|
12 | 12 | describe('react-tv init', () => {
|
13 |
| - let slug = 'react-tv' |
| 13 | + let slug = 'react-tv'; |
14 | 14 |
|
15 |
| - beforeEach((done) => rimraf(path.resolve(packagePath, slug), done)) |
16 |
| - afterEach((done) => rimraf(path.resolve(packagePath, slug), done)) |
| 15 | + beforeEach(done => rimraf(path.resolve(packagePath, slug), done)); |
| 16 | + afterEach(done => rimraf(path.resolve(packagePath, slug), done)); |
17 | 17 |
|
18 | 18 | it('should create react-tv folder', () => {
|
19 |
| - const subject = spawnSync('node', [ |
20 |
| - scriptPath, |
21 |
| - 'init' |
22 |
| - ], { cwd: packagePath }) |
| 19 | + const subject = spawnSync('node', [scriptPath, 'init'], { |
| 20 | + cwd: packagePath, |
| 21 | + }); |
23 | 22 |
|
24 |
| - const createdAppPath = path.resolve(packagePath, slug) |
25 |
| - const appInfo = require(path.resolve(createdAppPath, 'webos/appinfo.json')) |
| 23 | + const createdAppPath = path.resolve(packagePath, slug); |
| 24 | + const appInfo = require(path.resolve( |
| 25 | + createdAppPath, |
| 26 | + 'webos/appinfo.json' |
| 27 | + )); |
26 | 28 |
|
27 |
| - expect(appInfo.id).toEqual('react.tv.app') |
28 |
| - expect(appInfo.title).toEqual('package') |
29 |
| - expect(subject).toRunSuccessfully() |
30 |
| - }) |
| 29 | + expect(appInfo.id).toEqual('react.tv.app'); |
| 30 | + expect(appInfo.title).toEqual('package'); |
| 31 | + expect(subject).toRunSuccessfully(); |
| 32 | + }); |
31 | 33 |
|
32 | 34 | it('should fail when package.json not exists', () => {
|
33 |
| - const subject = spawnSync('node', [ |
34 |
| - scriptPath, |
35 |
| - 'init' |
36 |
| - ], { cwd: emptyPackagePath }) |
| 35 | + const subject = spawnSync('node', [scriptPath, 'init'], { |
| 36 | + cwd: fixturesPath, |
| 37 | + }); |
37 | 38 |
|
38 |
| - expect(subject).not.toRunSuccessfully() |
39 |
| - }) |
40 |
| - }) |
| 39 | + expect(subject).not.toRunSuccessfully(); |
| 40 | + }); |
| 41 | + }); |
41 | 42 |
|
42 | 43 | describe('react-tv init <appName>', () => {
|
43 |
| - const appName = 'russell-crowe' |
| 44 | + const appName = 'russell-crowe'; |
44 | 45 |
|
45 |
| - beforeEach((done) => rimraf(path.resolve(emptyPackagePath, appName), done)) |
46 |
| - afterEach((done) => rimraf(path.resolve(emptyPackagePath, appName), done)) |
| 46 | + beforeEach(done => rimraf(path.resolve(fixturesPath, appName), done)); |
| 47 | + afterEach(done => rimraf(path.resolve(fixturesPath, appName), done)); |
47 | 48 |
|
48 | 49 | it('should create custom app', () => {
|
49 |
| - const subject = spawnSync('node', [ |
50 |
| - scriptPath, |
51 |
| - 'init', |
52 |
| - appName |
53 |
| - ], { cwd: emptyPackagePath }) |
54 |
| - |
55 |
| - const createdAppPath = path.resolve(emptyPackagePath, appName) |
56 |
| - const createdPackageJson = require(path.resolve(createdAppPath, 'package.json')) |
57 |
| - |
58 |
| - expect(subject).toRunSuccessfully() |
59 |
| - expect(createdPackageJson.name).toEqual('russell-crowe') |
60 |
| - }) |
61 |
| - }) |
62 |
| -}) |
| 50 | + const subject = spawnSync('node', [scriptPath, 'init', appName], { |
| 51 | + cwd: fixturesPath, |
| 52 | + }); |
| 53 | + |
| 54 | + const createdAppPath = path.resolve(fixturesPath, appName); |
| 55 | + const createdPackageJson = require(path.resolve( |
| 56 | + createdAppPath, |
| 57 | + 'package.json' |
| 58 | + )); |
| 59 | + |
| 60 | + expect(subject).toRunSuccessfully(); |
| 61 | + expect(createdPackageJson.name).toEqual('russell-crowe'); |
| 62 | + }); |
| 63 | + }); |
| 64 | +}); |
0 commit comments