This repository was archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.test.js
95 lines (85 loc) · 3.2 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// End-to-end Integration Test
const fs = require('fs')
const { execSync } = require('child_process')
const rimraf = require('rimraf')
const { error } = require('./helpers/logger')
const tmpDir = `tmp-${Math.floor(Math.random() * 1000000)}`
// TODO: Jest can't process coverage of spaned processes
// May need to wrap NYC to get the coverage of all the
// code executed here
// https://github.com/amclin/react-project-boilerplate/issues/28
describe('Integration Test', () => {
describe('Generated App', () => {
beforeAll(async () => {
// Run the generator expecting successful STDOUT
try {
await execSync(
`node ./index.js --use-npm --no-git --with-ssr -- ${tmpDir}`,
{ stdio: 'inherit' }
)
} catch (e) {
error('Failed to complete generation process.', e)
expect(true).toEqual(false) // Force test failure
}
})
afterAll(() => {
// Cleanup the temp
rimraf.sync(`./${tmpDir}`, {}, () => {
error(`No tmp directory (${tmpDir}) to remove.`)
expect(true).toEqual(false) // Force test failure
})
})
it('can build', async () => {
// Generated app should be buildable
try {
await execSync(`(cd ${tmpDir} ; npm run build)`, { stdio: 'inherit' })
} catch (e) {
error('Generated app failed to build with `npm run build`', e)
expect(true).toEqual(false) // Force test failure
}
})
it('can export static html', async () => {
// Generated app should be exportable
try {
await execSync(`(cd ${tmpDir} ; npm run export)`, { stdio: 'inherit' })
} catch (e) {
error('Generated app failed to export with `npm run export`', e)
expect(true).toEqual(false) // Force test failure
}
})
describe('New component wizard(plop)', () => {
const componentTypes = {
atom: {
files: ['index.js', 'MockComponent.jsx', 'MockComponent.test.jsx']
},
molecule: {
files: ['index.js', 'MockComponent.jsx', 'MockComponent.test.jsx']
},
organism: {
files: ['index.js', 'MockComponent.jsx', 'MockComponent.test.jsx']
}
}
// Loop through each type of component and test the files are created
Object.entries(componentTypes).forEach(([componentType, data]) => {
it(`can generate new ${componentType}s through the wizard`, async () => {
const path = `${tmpDir}/src/components/${componentType}s/MockComponent`
const cmd = `(cd ${tmpDir}; npm run generate -- component ${componentType} "mock component" "short description")`
try {
await execSync(cmd)
} catch (e) {
error(`Failed to run plop for a ${componentType}`, e)
expect(true).toEqual(false) // Force test failure
}
// Check that all expected files are generated
data.files.forEach(file => {
expect(
fs.readFileSync(`${path}/${file}`, 'utf-8')
).toMatchSnapshot()
})
})
})
it.skip('can generate new pages through the wizard', async () => {})
it.skip('can generate new apis through the wizard', async () => {})
})
})
})