|
1 | 1 | import fs from 'fs'; |
2 | 2 | import path from 'path'; |
3 | 3 |
|
4 | | -import run from '../test-utils'; |
| 4 | +import { rmTestDir, run } from '../test-utils'; |
5 | 5 |
|
6 | 6 | jest.setTimeout(240000); |
7 | 7 |
|
8 | 8 | const testDirPath = path.join(__dirname, 'test-app'); |
9 | 9 |
|
10 | 10 | beforeEach(() => { |
11 | | - if (fs.existsSync(testDirPath)) { |
12 | | - fs.rmdirSync(testDirPath, { recursive: true }); |
13 | | - } |
| 11 | + rmTestDir(testDirPath); |
14 | 12 | }); |
15 | 13 |
|
16 | 14 | afterAll(() => { |
17 | | - fs.rmdirSync(testDirPath, { recursive: true }); |
| 15 | + rmTestDir(testDirPath); |
18 | 16 | }); |
19 | 17 |
|
20 | 18 | const generatedFiles = [ |
@@ -59,7 +57,7 @@ describe('new command', () => { |
59 | 57 | // Assertion for the configured scripts |
60 | 58 | expect(pkgJson.name).toBe('test-app'); |
61 | 59 | expect(pkgJson.scripts['build']).toBe('webpack'); |
62 | | - expect(pkgJson.scripts['serve']).toBe('webpack-dev-server --open'); |
| 60 | + expect(pkgJson.scripts['serve']).toBe('webpack serve'); |
63 | 61 | }); |
64 | 62 |
|
65 | 63 | it('uses npm on supplying --use-npm', async () => { |
@@ -90,6 +88,38 @@ describe('new command', () => { |
90 | 88 | // Assertion for the configured scripts |
91 | 89 | expect(pkgJson.name).toBe('test-app'); |
92 | 90 | expect(pkgJson.scripts['build']).toBe('webpack'); |
93 | | - expect(pkgJson.scripts['serve']).toBe('webpack-dev-server --open'); |
| 91 | + expect(pkgJson.scripts['serve']).toBe('webpack serve'); |
| 92 | + |
| 93 | + // Remove test-app directory |
| 94 | + rmTestDir(testDirPath); |
| 95 | + }); |
| 96 | + |
| 97 | + it('creates a project in the current directory', async () => { |
| 98 | + // Create test-app directory |
| 99 | + fs.mkdirSync(testDirPath); |
| 100 | + |
| 101 | + const { exitCode } = await run(['new', '.'], { |
| 102 | + cwd: testDirPath, |
| 103 | + input: '\n', |
| 104 | + }); |
| 105 | + |
| 106 | + // Assertions |
| 107 | + expect(exitCode).toBe(0); |
| 108 | + generatedFiles.forEach(file => |
| 109 | + expect(fs.existsSync(path.join(testDirPath, file))).toBeTruthy() |
| 110 | + ); |
| 111 | + |
| 112 | + const pkgJson = JSON.parse( |
| 113 | + fs.readFileSync(path.join(testDirPath, 'package.json')) |
| 114 | + ); |
| 115 | + |
| 116 | + // Assertion for the installed dependencies |
| 117 | + expect(pkgJson.dependencies).toBeFalsy(); |
| 118 | + deps.forEach(dep => expect(pkgJson.devDependencies[dep]).toBeTruthy()); |
| 119 | + |
| 120 | + // Assertion for the configured scripts |
| 121 | + expect(pkgJson.name).toBe('test-app'); |
| 122 | + expect(pkgJson.scripts['build']).toBe('webpack'); |
| 123 | + expect(pkgJson.scripts['serve']).toBe('webpack serve'); |
94 | 124 | }); |
95 | 125 | }); |
0 commit comments