|
| 1 | +const { spawnSync } = require('child_process') |
| 2 | +const path = require('path') |
| 3 | +const rimraf = require('rimraf') |
| 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') |
| 8 | + |
| 9 | +require('./to-run-successfully-matcher') |
| 10 | + |
| 11 | +describe('[CLI] init', () => { |
| 12 | + describe('react-tv init', () => { |
| 13 | + let slug = 'react-tv' |
| 14 | + |
| 15 | + beforeEach((done) => rimraf(path.resolve(packagePath, slug), done)) |
| 16 | + afterEach((done) => rimraf(path.resolve(packagePath, slug), done)) |
| 17 | + |
| 18 | + it('should create react-tv folder', () => { |
| 19 | + const subject = spawnSync('node', [ |
| 20 | + scriptPath, |
| 21 | + 'init' |
| 22 | + ], { cwd: packagePath }) |
| 23 | + |
| 24 | + const createdAppPath = path.resolve(packagePath, slug) |
| 25 | + const appInfo = require(path.resolve(createdAppPath, 'webos/appinfo.json')) |
| 26 | + |
| 27 | + expect(appInfo.id).toEqual('react.tv.app') |
| 28 | + expect(appInfo.title).toEqual('package') |
| 29 | + expect(subject).toRunSuccessfully() |
| 30 | + }) |
| 31 | + |
| 32 | + it('should fail when package.json not exists', () => { |
| 33 | + const subject = spawnSync('node', [ |
| 34 | + scriptPath, |
| 35 | + 'init' |
| 36 | + ], { cwd: emptyPackagePath }) |
| 37 | + |
| 38 | + expect(subject).not.toRunSuccessfully() |
| 39 | + }) |
| 40 | + }) |
| 41 | + |
| 42 | + describe('react-tv init <appName>', () => { |
| 43 | + const appName = 'russell-crowe' |
| 44 | + |
| 45 | + beforeEach((done) => rimraf(path.resolve(emptyPackagePath, appName), done)) |
| 46 | + afterEach((done) => rimraf(path.resolve(emptyPackagePath, appName), done)) |
| 47 | + |
| 48 | + 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 | +}) |
0 commit comments