diff --git a/.gitignore b/.gitignore index 56c9105e..8813d049 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ build out .next /coverage -/tmp +/tmp-* diff --git a/helpers/populate-project.test.js b/helpers/populate-project.test.js index 5b3278a3..ed3940e5 100644 --- a/helpers/populate-project.test.js +++ b/helpers/populate-project.test.js @@ -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 @@ -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.`) }) }) diff --git a/index.test.js b/index.test.js index af258d5a..b76baac1 100644 --- a/index.test.js +++ b/index.test.js @@ -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 () => {}) + }) }) }) -}) diff --git a/package-lock.json b/package-lock.json index 46e3563e..72cc935f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "create-amclin-nextjs-app", - "version": "3.5.1", + "version": "3.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 65089dde..397f50e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "create-amclin-nextjs-app", - "version": "3.6.0", + "version": "3.6.1", "description": "Boilerplate repo for React apps with CICD pipelines, best practices, and code governance", "repository": { "type": "git", @@ -93,7 +93,7 @@ "/.next/", "/node_modules/", "/coverage/", - "/tmp/", + "/tmp-*/", "/__mocks__/" ], "coverageReporters": [ @@ -117,7 +117,7 @@ "/build/", "/out/", "/coverage/", - "/tmp/" + "/tmp-*/" ], "transform": { "^.+\\.[t|j]sx?$": "babel-jest"