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

Commit

Permalink
fix(test command): tmp dir now use random int to not conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Danikowski authored and Kevin Danikowski committed Nov 27, 2019
1 parent 8e7f739 commit 36bffdf
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ build
out
.next
/coverage
/tmp
/tmp-*
10 changes: 5 additions & 5 deletions helpers/populate-project.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const rimraf = require('rimraf')
const { populateProject } = require('./populate-project')
const { log, error } = require('./logger')

const tmpDir = 'tmp'
const tmpDir = `tmp-${Math.floor(Math.random() * 1000000)}`
const tmpFile = `${tmpDir}/testPopulateProject.md`
const mockMd = `
sample content
Expand All @@ -18,14 +18,14 @@ const mockMd = `
describe('populate-project', () => {
beforeEach(() => {
// Cleanup the temp
rimraf.sync('./tmp', {}, () => {
log('Could not remove tmp directory before test.')
rimraf.sync(`./${tmpDir}`, {}, () => {
log(`Could not remove tmp directory (${tmpDir}) before test.`)
})
})
afterEach(() => {
// Cleanup the temp
rimraf.sync('./tmp', {}, () => {
log('Could not remove tmp directory after test.')
rimraf.sync(`./${tmpDir}`, {}, () => {
log(`Could not remove tmp directory (${tmpDir}) after test.`)
})
})

Expand Down
145 changes: 70 additions & 75 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,97 +4,92 @@ 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 -- tmp', { stdio: 'inherit' })
} catch (e) {
error('Failed to complete generation process.', e)
expect(true).toEqual(false) // Force test failure
}
})
afterAll(() => {
// Cleanup the temp
rimraf.sync('./tmp', {}, () => {
error('No tmp directory to remove.')
expect(true).toEqual(false) // Force test failure
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 tmp ; 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 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 tmp ; 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
}
})
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'
]
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 = `tmp/src/components/${componentType}s/MockComponent`
const cmd = `(cd tmp; npm run generate -- component ${componentType} "mock component" "short description")`
// 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
}
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()
// 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 () => {})
it.skip('can generate new pages through the wizard', async () => {})
it.skip('can generate new apis through the wizard', async () => {})
})
})
})
})
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"<rootDir>/.next/",
"<rootDir>/node_modules/",
"<rootDir>/coverage/",
"<rootDir>/tmp/",
"<rootDir>/tmp-*/",
"/__mocks__/"
],
"coverageReporters": [
Expand All @@ -117,7 +117,7 @@
"<rootDir>/build/",
"<rootDir>/out/",
"<rootDir>/coverage/",
"<rootDir>/tmp/"
"<rootDir>/tmp-*/"
],
"transform": {
"^.+\\.[t|j]sx?$": "babel-jest"
Expand Down

0 comments on commit 36bffdf

Please sign in to comment.