-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from alexlee-dev/v0.8.0
📦 v0.8.0
- Loading branch information
Showing
15 changed files
with
219 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.