Skip to content

Commit

Permalink
chore: rename starter template directory (#200)
Browse files Browse the repository at this point in the history
* fix(#196): temp file change

* fix(#196): pwa starter template folder name fix to PWA

* test: add test case for init with PWA starter template

* chore: leverage jest globals

* fix: lint

Co-authored-by: jamesgeorge007 <jamesgeorge998001@gmail.com>
  • Loading branch information
danivijay and jamesgeorge007 authored Nov 4, 2020
1 parent 2f7c659 commit f56577b
Show file tree
Hide file tree
Showing 39 changed files with 45 additions and 15 deletions.
4 changes: 1 addition & 3 deletions __e2e__/commands/add.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { DOWN, ENTER, SPACE } from 'cli-prompts-test';
import fs from 'fs';
import path from 'path';

// Create a temp directory
const tempDirPath = path.join(__dirname, 'add-cmd');
fs.mkdirSync(tempDirPath);

const genPath = path.join(tempDirPath, 'my-app');

// The client directory
Expand All @@ -18,6 +15,7 @@ const serverPath = path.join(genPath, 'server');

describe('mevn add', () => {
// cleanup
beforeAll(() => fs.mkdirSync(tempDirPath));
afterAll(() => rmTempDir(tempDirPath));

it('installs Nuxt.js modules if no args were passed in', async () => {
Expand Down
5 changes: 2 additions & 3 deletions __e2e__/commands/codesplit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import { DOWN, ENTER } from 'cli-prompts-test';
import fs from 'fs';
import path from 'path';

// Create a temp directory
const tempDirPath = path.join(__dirname, 'codesplit-cmd');
fs.mkdirSync(tempDirPath);

const genPath = path.join(tempDirPath, 'my-app');

// The client directory
const clientPath = path.join(genPath, 'client');

describe('mevn codesplit', () => {
// Cleanup
beforeAll(() => fs.mkdirSync(tempDirPath));
afterAll(() => rmTempDir(tempDirPath));

it('dynamically imports a component', async () => {
Expand Down
6 changes: 2 additions & 4 deletions __e2e__/commands/generate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { DOWN, ENTER } from 'cli-prompts-test';
import fs from 'fs';
import path from 'path';

// Create a temp directory
const tempDirPath = path.join(__dirname, 'generate-cmd');
fs.mkdirSync(tempDirPath);

const genPath = path.join(tempDirPath, 'my-app');

// The client directory
Expand All @@ -23,7 +20,8 @@ const pageComponentPath = path.join(clientPath, 'src', 'views');
const serverPath = path.join(genPath, 'server');

describe('mevn generate', () => {
// cleanup
// Cleanup
beforeAll(() => fs.mkdirSync(tempDirPath));
afterAll(() => rmTempDir(tempDirPath));

it('generates a UI component', async () => {
Expand Down
45 changes: 40 additions & 5 deletions __e2e__/commands/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ import { DOWN, ENTER } from 'cli-prompts-test';
import fs from 'fs';
import path from 'path';

// Create a temp directory
const tempDirPath = path.join(__dirname, 'init-cmd');
fs.mkdirSync(tempDirPath);

const genPath = path.join(tempDirPath, 'my-app');

const clientPath = path.join(genPath, 'client');
const serverPath = path.join(genPath, 'server');

describe('mevn init', () => {
// Cleanup
beforeAll(() => fs.mkdirSync(tempDirPath));
afterAll(() => rmTempDir(tempDirPath));

it('shows an appropriate warning if multiple arguments were provided with init', () => {
Expand All @@ -37,7 +36,7 @@ describe('mevn init', () => {
`${DOWN}${DOWN}${DOWN}${ENTER}`, // Choose Nuxt.js as the starter template
`${DOWN}${ENTER}`, // Choose spa as the rendering mode
`${DOWN}${ENTER}`, // Choose static as the deploy target
`Y${ENTER}`, // Requires server directory
`${ENTER}`, // Requires server directory
],
tempDirPath,
);
Expand Down Expand Up @@ -88,18 +87,54 @@ describe('mevn init', () => {
['init', 'my-app'],
[
`${DOWN}${DOWN}${ENTER}`, // Choose GraphQL as the starter template
`Y${ENTER}`, // Requires server directory
`${ENTER}`, // Requires server directory
],
tempDirPath,
);

expect(fetchProjectConfig(genPath).template).toBe('GraphQL');
expect(fetchProjectConfig(genPath).isConfigured.client).toBe(false);
expect(fetchProjectConfig(genPath).isConfigured.server).toBe(false);

// Rename .mevngitignore to .gitignore
expect(fs.existsSync(path.join(clientPath, '.mevngitignore'))).toBeFalsy();
expect(fs.existsSync(path.join(clientPath, '.gitignore'))).toBeTruthy();

// Check whether if the respective directory have been generated
expect(fs.existsSync(path.join(serverPath, 'graphql'))).toBeTruthy();

// Delete the generated directory
rmTempDir(genPath);
});

it('creates a new MEVN stack webapp based on the PWA starter template', async () => {
await runPromptWithAnswers(
['init', 'my-app'],
[
`${DOWN}${ENTER}`, // Choose PWA as the starter template
`${ENTER}`, // Requires server directory
],
tempDirPath,
);

expect(fetchProjectConfig(genPath).template).toBe('PWA');
expect(fetchProjectConfig(genPath).isConfigured.client).toBe(false);
expect(fetchProjectConfig(genPath).isConfigured.server).toBe(false);

// Rename .mevngitignore to .gitignore
expect(fs.existsSync(path.join(clientPath, '.mevngitignore'))).toBeFalsy();
expect(fs.existsSync(path.join(clientPath, '.gitignore'))).toBeTruthy();

// Check whether if the respective directory have been generated
expect(fs.existsSync(path.join(serverPath))).toBeTruthy();

// Assert for files specific to the starter template
expect(fs.existsSync(path.join(clientPath, 'public', 'img'))).toBeTruthy();
expect(
fs.existsSync(path.join(clientPath, 'public', 'manifest.json')),
).toBeTruthy();
expect(
fs.existsSync(path.join(clientPath, 'src', 'registerServiceWorker.js')),
).toBeTruthy();
});
});

0 comments on commit f56577b

Please sign in to comment.