Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit 019e47e

Browse files
Merge pull request #119 from amclin/fix/kevin-test-run
Fix/kevin test run
2 parents 1542a58 + 37e7df1 commit 019e47e

File tree

5 files changed

+1226
-1389
lines changed

5 files changed

+1226
-1389
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ build
99
out
1010
.next
1111
/coverage
12-
/tmp
12+
/tmp-*

helpers/populate-project.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const rimraf = require('rimraf')
44
const { populateProject } = require('./populate-project')
55
const { log, error } = require('./logger')
66

7-
const tmpDir = 'tmp'
7+
const tmpDir = `tmp-${Math.floor(Math.random() * 1000000)}`
88
const tmpFile = `${tmpDir}/testPopulateProject.md`
99
const mockMd = `
1010
sample content
@@ -18,14 +18,14 @@ const mockMd = `
1818
describe('populate-project', () => {
1919
beforeEach(() => {
2020
// Cleanup the temp
21-
rimraf.sync('./tmp', {}, () => {
22-
log('Could not remove tmp directory before test.')
21+
rimraf.sync(`./${tmpDir}`, {}, () => {
22+
log(`Could not remove tmp directory (${tmpDir}) before test.`)
2323
})
2424
})
2525
afterEach(() => {
2626
// Cleanup the temp
27-
rimraf.sync('./tmp', {}, () => {
28-
log('Could not remove tmp directory after test.')
27+
rimraf.sync(`./${tmpDir}`, {}, () => {
28+
log(`Could not remove tmp directory (${tmpDir}) after test.`)
2929
})
3030
})
3131

index.test.js

Lines changed: 70 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,97 +4,92 @@ const { execSync } = require('child_process')
44
const rimraf = require('rimraf')
55
const { error } = require('./helpers/logger')
66

7+
const tmpDir = `tmp-${Math.floor(Math.random() * 1000000)}`
8+
79
// TODO: Jest can't process coverage of spaned processes
810
// May need to wrap NYC to get the coverage of all the
911
// code executed here
1012
// https://github.com/amclin/react-project-boilerplate/issues/28
1113

1214
describe('Integration Test', () => {
13-
describe('Generated App', () => {
14-
beforeAll( async () => {
15-
// Run the generator expecting successful STDOUT
16-
try {
17-
await execSync('node ./index.js --use-npm --no-git --with-ssr -- tmp', { stdio: 'inherit' })
18-
} catch (e) {
19-
error('Failed to complete generation process.', e)
20-
expect(true).toEqual(false) // Force test failure
21-
}
22-
})
23-
afterAll(() => {
24-
// Cleanup the temp
25-
rimraf.sync('./tmp', {}, () => {
26-
error('No tmp directory to remove.')
27-
expect(true).toEqual(false) // Force test failure
15+
describe('Generated App', () => {
16+
beforeAll(async () => {
17+
// Run the generator expecting successful STDOUT
18+
try {
19+
await execSync(
20+
`node ./index.js --use-npm --no-git --with-ssr -- ${tmpDir}`,
21+
{ stdio: 'inherit' }
22+
)
23+
} catch (e) {
24+
error('Failed to complete generation process.', e)
25+
expect(true).toEqual(false) // Force test failure
26+
}
27+
})
28+
afterAll(() => {
29+
// Cleanup the temp
30+
rimraf.sync(`./${tmpDir}`, {}, () => {
31+
error(`No tmp directory (${tmpDir}) to remove.`)
32+
expect(true).toEqual(false) // Force test failure
33+
})
2834
})
29-
})
3035

31-
it('can build', async () => {
32-
// Generated app should be buildable
33-
try {
34-
await execSync('(cd tmp ; npm run build)', { stdio: 'inherit' })
35-
} catch (e) {
36-
error('Generated app failed to build with `npm run build`', e)
37-
expect(true).toEqual(false) // Force test failure
38-
}
39-
})
36+
it('can build', async () => {
37+
// Generated app should be buildable
38+
try {
39+
await execSync(`(cd ${tmpDir} ; npm run build)`, { stdio: 'inherit' })
40+
} catch (e) {
41+
error('Generated app failed to build with `npm run build`', e)
42+
expect(true).toEqual(false) // Force test failure
43+
}
44+
})
4045

41-
it('can export static html', async () => {
42-
// Generated app should be exportable
43-
try {
44-
await execSync('(cd tmp ; npm run export)', { stdio: 'inherit' })
45-
} catch (e) {
46-
error('Generated app failed to export with `npm run export`', e)
47-
expect(true).toEqual(false) // Force test failure
48-
}
49-
})
46+
it('can export static html', async () => {
47+
// Generated app should be exportable
48+
try {
49+
await execSync(`(cd ${tmpDir} ; npm run export)`, { stdio: 'inherit' })
50+
} catch (e) {
51+
error('Generated app failed to export with `npm run export`', e)
52+
expect(true).toEqual(false) // Force test failure
53+
}
54+
})
5055

51-
describe('New component wizard(plop)', () => {
52-
const componentTypes = {
53-
atom: {
54-
files: [
55-
'index.js',
56-
'MockComponent.jsx',
57-
'MockComponent.test.jsx'
58-
]
59-
},
60-
molecule: {
61-
files: [
62-
'index.js',
63-
'MockComponent.jsx',
64-
'MockComponent.test.jsx'
65-
]
66-
},
67-
organism: {
68-
files: [
69-
'index.js',
70-
'MockComponent.jsx',
71-
'MockComponent.test.jsx'
72-
]
56+
describe('New component wizard(plop)', () => {
57+
const componentTypes = {
58+
atom: {
59+
files: ['index.js', 'MockComponent.jsx', 'MockComponent.test.jsx']
60+
},
61+
molecule: {
62+
files: ['index.js', 'MockComponent.jsx', 'MockComponent.test.jsx']
63+
},
64+
organism: {
65+
files: ['index.js', 'MockComponent.jsx', 'MockComponent.test.jsx']
66+
}
7367
}
74-
}
7568

76-
// Loop through each type of component and test the files are created
77-
Object.entries(componentTypes).forEach(([componentType, data]) => {
78-
it(`can generate new ${componentType}s through the wizard`, async() => {
79-
const path = `tmp/src/components/${componentType}s/MockComponent`
80-
const cmd = `(cd tmp; npm run generate -- component ${componentType} "mock component" "short description")`
69+
// Loop through each type of component and test the files are created
70+
Object.entries(componentTypes).forEach(([componentType, data]) => {
71+
it(`can generate new ${componentType}s through the wizard`, async () => {
72+
const path = `${tmpDir}/src/components/${componentType}s/MockComponent`
73+
const cmd = `(cd ${tmpDir}; npm run generate -- component ${componentType} "mock component" "short description")`
8174

82-
try {
83-
await execSync(cmd)
84-
} catch (e) {
85-
error(`Failed to run plop for a ${componentType}`, e)
86-
expect(true).toEqual(false) // Force test failure
87-
}
75+
try {
76+
await execSync(cmd)
77+
} catch (e) {
78+
error(`Failed to run plop for a ${componentType}`, e)
79+
expect(true).toEqual(false) // Force test failure
80+
}
8881

89-
// Check that all expected files are generated
90-
data.files.forEach((file) => {
91-
expect(fs.readFileSync(`${path}/${file}`, 'utf-8')).toMatchSnapshot()
82+
// Check that all expected files are generated
83+
data.files.forEach(file => {
84+
expect(
85+
fs.readFileSync(`${path}/${file}`, 'utf-8')
86+
).toMatchSnapshot()
87+
})
9288
})
9389
})
94-
})
9590

96-
it.skip('can generate new pages through the wizard', async () => {})
97-
it.skip('can generate new apis through the wizard', async () => {})
91+
it.skip('can generate new pages through the wizard', async () => {})
92+
it.skip('can generate new apis through the wizard', async () => {})
93+
})
9894
})
9995
})
100-
})

0 commit comments

Comments
 (0)