Skip to content

Commit

Permalink
Merge pull request #32 from alexlee-dev/v0.8.0
Browse files Browse the repository at this point in the history
📦 v0.8.0
  • Loading branch information
Alex Lee authored Jun 12, 2020
2 parents 6200c9b + 8a4514c commit 112d4e9
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 553 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.0] - 2020-06-11

### 🧪 Good Testing

### Added

### Changed

- Enhanced Testing - [#27](https://github.com/alexlee-dev/create-mern-application/issues/27)
- Rewrote `valueReplacer()` to be more robust - [#29](https://github.com/alexlee-dev/create-mern-application/issues/29)
- Use own `replace()` instead of relying on `replace` dependency - [#28](https://github.com/alexlee-dev/create-mern-application/issues/28)

### Removed

- Check for `pathExists` - [#31](https://github.com/alexlee-dev/create-mern-application/issues/31)

### Fixed

## [0.7.0] - 2020-06-10

### 🏗️ Build JS from TS
Expand Down
186 changes: 58 additions & 128 deletions __tests__/application.test.js
Original file line number Diff line number Diff line change
@@ -1,156 +1,86 @@
import { describe, expect, it, test } from "@jest/globals";
import { describe, test } from "@jest/globals";
import fs from "fs-extra";
import ora from "ora";
import path from "path";
import { executeCommand } from "../build/util";
import { fileMatcher } from "./util";
import { startApplication } from "./util";

describe("create-mern-application", () => {
test("Create a JavaScript MERN application", async () => {
const root = path.resolve("test-application");
const root = path.resolve("test-application-js");

let verificationArr;
let spinner = ora("Creating JS application");

try {
await executeCommand("create-mern-application", ["test-application"]);

const templateBase = path.join(__dirname, "../src/template");

const filesToVerify = [
{
src: path.join(root, ".babelrc"),
fileContentsSrc: path.join(templateBase, "/babelrc"),
},
{
src: path.join(root, ".env-cmdrc.json"),
fileContentsSrc: path.join(__dirname, "./fixtures/.env-cmdrc.json"),
},
{
src: path.join(root, ".gitignore"),
fileContentsSrc: path.join(templateBase, "gitignore"),
},
{
src: path.join(root, "package.json"),
fileContentsSrc: path.join(__dirname, "./fixtures/package-js.json"),
},
{
src: path.join(root, "/public/index.html"),
fileContentsSrc: path.join(__dirname, "./fixtures/index.html"),
},
{
src: path.join(root, "README.md"),
fileContentsSrc: path.join(__dirname, "./fixtures/README.md"),
},
{
src: path.join(root, "webpack.config.js"),
fileContentsSrc: path.join(templateBase, "webpack-js.js"),
},
{
src: path.join(root, "/src/server/assets/site.webmanifest"),
fileContentsSrc: path.join(__dirname, "./fixtures/site.webmanifest"),
},
];

verificationArr = await Promise.all(
filesToVerify.map(async ({ src, fileContentsSrc }) => {
const fileContents = await fs.readFile(fileContentsSrc);
const doesFileMatch = await fileMatcher(src, fileContents);
return { doesFileMatch, src };
})
);

await executeCommand("rimraf", [root], {
// * Create Application
spinner.start();
await executeCommand("create-mern-application", ["test-application-js"], {
shell: process.platform === "win32",
});
} catch (error) {
await executeCommand("rimraf", [root], {
spinner.succeed("JS application created successfully");

// * Build Application
spinner = ora("Building application").start();
await executeCommand("npm", ["run", "build"], {
cwd: root,
shell: process.platform === "win32",
});
spinner.succeed("Application successfully built");

// * Start Application
spinner = ora("Starting application").start();
await startApplication(root, spinner);

// * Cleanup
spinner = ora("Performing cleanup").start();
await fs.remove(root);
spinner.succeed("Cleanup successful");
} catch (error) {
spinner.fail();
console.log("");
await fs.remove(root);
throw new Error(error);
}

expect(verificationArr).toEqual(
verificationArr.map(({ src }) => ({
doesFileMatch: true,
src,
}))
);
}, 120000);
}, 180000);

test("Create a TypeScript MERN application", async () => {
const root = path.resolve("test-application");
const root = path.resolve("test-application-ts");

let verificationArr;
let spinner = ora("Creating TS application");

try {
await executeCommand("create-mern-application", [
"test-application",
"--typescript",
]);

const templateBase = path.join(__dirname, "../src/template");

const filesToVerify = [
{
src: path.join(root, ".env-cmdrc.json"),
fileContentsSrc: path.join(__dirname, "./fixtures/.env-cmdrc.json"),
},
{
src: path.join(root, ".gitignore"),
fileContentsSrc: path.join(templateBase, "gitignore"),
},
{
src: path.join(root, "index.d.ts"),
fileContentsSrc: path.join(templateBase, "/ts/index.d.ts"),
},
{
src: path.join(root, "package.json"),
fileContentsSrc: path.join(__dirname, "./fixtures/package-ts.json"),
},
{
src: path.join(root, "/public/index.html"),
fileContentsSrc: path.join(__dirname, "./fixtures/index.html"),
},
{
src: path.join(root, "README.md"),
fileContentsSrc: path.join(__dirname, "./fixtures/README.md"),
},
{
src: path.join(root, "tsconfig.json"),
fileContentsSrc: path.join(__dirname, "./fixtures/tsconfig.json"),
},
{
src: path.join(root, "webpack.config.js"),
fileContentsSrc: path.join(templateBase, "webpack-ts.js"),
},
{
src: path.join(root, "/src/server/assets/site.webmanifest"),
fileContentsSrc: path.join(__dirname, "./fixtures/site.webmanifest"),
},
];

verificationArr = await Promise.all(
filesToVerify.map(async ({ src, fileContentsSrc }) => {
const fileContents = await fs.readFile(fileContentsSrc);
const doesFileMatch = await fileMatcher(src, fileContents);
return { doesFileMatch, src };
})
// * Create Application
spinner.start();
await executeCommand(
"create-mern-application",
["test-application-ts", "--typescript"],
{
shell: process.platform === "win32",
}
);
spinner.succeed("TS application created successfully");

await executeCommand("rimraf", [root], {
// * Build Application
spinner = ora("Building application").start();
await executeCommand("npm", ["run", "build"], {
cwd: root,
shell: process.platform === "win32",
});
spinner.succeed("Application successfully built");

// * Start Application
spinner = ora("Starting application").start();
await startApplication(root, spinner);

// * Cleanup
spinner = ora("Performing cleanup").start();
await fs.remove(root);
spinner.succeed("Cleanup successful");
} catch (error) {
await executeCommand("rimraf", [root], {
shell: process.platform === "win32",
});
spinner.fail();
console.log("");
await fs.remove(root);
throw new Error(error);
}

expect(verificationArr).toEqual(
verificationArr.map(({ src }) => ({
doesFileMatch: true,
src,
}))
);
}, 120000);
}, 180000);
});
20 changes: 0 additions & 20 deletions __tests__/fixtures/.env-cmdrc.json

This file was deleted.

36 changes: 0 additions & 36 deletions __tests__/fixtures/README.md

This file was deleted.

48 changes: 0 additions & 48 deletions __tests__/fixtures/index.html

This file was deleted.

51 changes: 0 additions & 51 deletions __tests__/fixtures/package-js.json

This file was deleted.

Loading

0 comments on commit 112d4e9

Please sign in to comment.