From b9786dde1add1cd04248e51f74588690aa996145 Mon Sep 17 00:00:00 2001 From: Matt Crowder Date: Tue, 12 Jun 2018 16:50:04 -0400 Subject: [PATCH 1/4] backup --- index.js | 5 +++++ index.spec.js | 35 +++++++++++++++++++++++++++++++++++ src/server/index.js | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 index.spec.js diff --git a/index.js b/index.js index 287b1ea..8fac3f1 100644 --- a/index.js +++ b/index.js @@ -118,8 +118,10 @@ program await fixPackageJson(); } catch (error) { if (!error.message.indexOf("File exists")) { + // eslint-disable-next-line no-console console.error("Something went wrong, sorry"); } else if (error.message.indexOf("File exists") !== -1) { + // eslint-disable-next-line no-console console.error(`You need to delete ${folder}, or run again with -f`); } } @@ -236,6 +238,7 @@ npm-debug.log`; const file = await readFile(`./${f}`); await writeFile(`${folder}/${f}`, file); } catch (e) { + // eslint-disable-next-line no-console console.log(e); throw e; } @@ -301,6 +304,7 @@ script: } fs.writeFile(filename, content, error => { if (error) { + // eslint-disable-next-line no-console console.log(error); reject(error); } else { @@ -308,6 +312,7 @@ script: } }); } catch (error) { + // eslint-disable-next-line no-console console.log(error); reject(error); } diff --git a/index.spec.js b/index.spec.js new file mode 100644 index 0000000..b8f18bc --- /dev/null +++ b/index.spec.js @@ -0,0 +1,35 @@ +const { exec } = require("child_process"); + +const executeFunction = func => { + return new Promise((resolve, reject) => { + try { + func((error, output) => { + if (error) { + reject(error); + } else { + resolve(output); + } + + }); + } catch (error) { + reject(error); + } + }); +}; +const e = (command, loadingText) => { + return executeFunction(callback => exec(command, callback), loadingText); +}; +const executeBuild = folder => { + return e(`cd ${folder} && npm test && npm run webpack && npm run bundlesize`); +}; +jest.setTimeout(90000); +test("standard", async () => { + const folder = "standard"; + try { + await e(`rm -rf ${folder}`); + await e(`node index.js ${folder}`); + await executeBuild(folder); + } finally { + await e(`rm -rf ${folder}`); + } +}); diff --git a/src/server/index.js b/src/server/index.js index c52b0ac..af971c6 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -13,5 +13,5 @@ app.get("*.js", (req, res, next) => { next(); }); app.use(express.static(path.resolve(__dirname, "../..", "build"))); - +// eslint-disable-next-line no-console app.listen(3000, () => console.log(`server started on port 3000`)); \ No newline at end of file From 6ac1fe521a60fa47249d2e8210101f13e6d3850c Mon Sep 17 00:00:00 2001 From: Matt Crowder Date: Tue, 12 Jun 2018 16:50:20 -0400 Subject: [PATCH 2/4] no standard --- .gitignore | 3 ++- build-index.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 91765f3..9e49130 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ bundle.js.map bundle.js index.html build -build/bundle.js.gz \ No newline at end of file +build/bundle.js.gz +standard \ No newline at end of file diff --git a/build-index.js b/build-index.js index 47ac69c..f4af516 100755 --- a/build-index.js +++ b/build-index.js @@ -249,6 +249,7 @@ program.arguments("").option("-y, --yarn", "Use yarn").option("-t, --tra _context3.prev = 16; _context3.t0 = _context3["catch"](8); + // eslint-disable-next-line no-console console.log(_context3.t0); throw _context3.t0; @@ -355,6 +356,7 @@ program.arguments("").option("-y, --yarn", "Use yarn").option("-t, --tra } fs.writeFile(filename, content, function (error) { if (error) { + // eslint-disable-next-line no-console console.log(error); reject(error); } else { @@ -362,6 +364,7 @@ program.arguments("").option("-y, --yarn", "Use yarn").option("-t, --tra } }); } catch (error) { + // eslint-disable-next-line no-console console.log(error); reject(error); } @@ -466,8 +469,10 @@ program.arguments("").option("-y, --yarn", "Use yarn").option("-t, --tra _context5.t0 = _context5["catch"](7); if (!_context5.t0.message.indexOf("File exists")) { + // eslint-disable-next-line no-console console.error("Something went wrong, sorry"); } else if (_context5.t0.message.indexOf("File exists") !== -1) { + // eslint-disable-next-line no-console console.error("You need to delete " + folder + ", or run again with -f"); } From f86c9b7818bae1d9d56fa0e8569f631251ba8fdb Mon Sep 17 00:00:00 2001 From: Matt Crowder Date: Tue, 12 Jun 2018 17:44:29 -0400 Subject: [PATCH 3/4] got some testsssss --- .gitignore | 8 +++++++- index-tests/git.spec.js | 8 ++++++++ index-tests/npm.spec.js | 11 +++++++++++ index-tests/skip.spec.js | 8 ++++++++ index-tests/travis.spec.js | 8 ++++++++ index-tests/utils.js | 33 +++++++++++++++++++++++++++++++++ index-tests/yarn.spec.js | 18 ++++++++++++++++++ index.spec.js | 35 ----------------------------------- package.json | 6 ++++-- test/client/config.js | 1 + 10 files changed, 98 insertions(+), 38 deletions(-) create mode 100644 index-tests/git.spec.js create mode 100644 index-tests/npm.spec.js create mode 100644 index-tests/skip.spec.js create mode 100644 index-tests/travis.spec.js create mode 100644 index-tests/utils.js create mode 100644 index-tests/yarn.spec.js delete mode 100644 index.spec.js diff --git a/.gitignore b/.gitignore index 9e49130..fefdd1f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,10 @@ bundle.js index.html build build/bundle.js.gz -standard \ No newline at end of file +standard +git +yarn +skip +npm +travis +yarn-skip \ No newline at end of file diff --git a/index-tests/git.spec.js b/index-tests/git.spec.js new file mode 100644 index 0000000..2589173 --- /dev/null +++ b/index-tests/git.spec.js @@ -0,0 +1,8 @@ +import { executeBashFunction, doesFileExist } from "./utils"; + +test("When passing -g, .gitignore should be created", async () => { + const folder = "git"; + await executeBashFunction(`node index.js ${folder} -s -g`); + const result = await doesFileExist(`${folder}/.gitignore`); + expect(result).toBeTruthy(); +}); \ No newline at end of file diff --git a/index-tests/npm.spec.js b/index-tests/npm.spec.js new file mode 100644 index 0000000..697881e --- /dev/null +++ b/index-tests/npm.spec.js @@ -0,0 +1,11 @@ +import { executeBashFunction, executeBuild, doesFileExist } from "./utils"; + +test("using npm", async () => { + const folder = "npm"; + await executeBashFunction(`node index.js ${folder}`); + await executeBuild(folder); + const doesPackageLockExist = await doesFileExist(`${folder}/package-lock.json`); + expect(doesPackageLockExist).toBeTruthy(); +}); + + diff --git a/index-tests/skip.spec.js b/index-tests/skip.spec.js new file mode 100644 index 0000000..13493ca --- /dev/null +++ b/index-tests/skip.spec.js @@ -0,0 +1,8 @@ +import { executeBashFunction, doesFileExist } from "./utils"; + +test("When passing -s, node_modules shouldn't be installed", async () => { + const folder = "skip"; + await executeBashFunction(`node index.js ${folder} -s`); + const result = await doesFileExist(`${folder}/node_modules`); + expect(result).not.toBeTruthy(); +}); diff --git a/index-tests/travis.spec.js b/index-tests/travis.spec.js new file mode 100644 index 0000000..abdbaf0 --- /dev/null +++ b/index-tests/travis.spec.js @@ -0,0 +1,8 @@ +import { executeBashFunction, doesFileExist } from "./utils"; + +test("When passing -t, .travis.yml should be created", async () => { + const folder = "travis"; + await executeBashFunction(`node index.js ${folder} -s -t`); + const result = await doesFileExist(`${folder}/.travis.yml`); + expect(result).toBeTruthy(); +}); \ No newline at end of file diff --git a/index-tests/utils.js b/index-tests/utils.js new file mode 100644 index 0000000..8a2550e --- /dev/null +++ b/index-tests/utils.js @@ -0,0 +1,33 @@ +const { exec } = require("child_process"); +const fs = require("fs-extra"); + +const executeFunction = func => { + return new Promise((resolve, reject) => { + try { + func((error, output) => { + if (error) { + reject(error); + } else { + resolve(output); + } + }); + } catch (error) { + reject(error); + } + }); +}; +export const executeBashFunction = command => { + return executeFunction(callback => exec(command, callback)); +}; +export const executeBuild = folder => { + return executeBashFunction(`cd ${folder} && npm test && npm run webpack && npm run bundlesize`); +}; + +export const doesFileExist = async path => { + try { + return await executeFunction(callback => fs.stat(path, callback)); + } catch (error) { + return false; + } + +}; \ No newline at end of file diff --git a/index-tests/yarn.spec.js b/index-tests/yarn.spec.js new file mode 100644 index 0000000..b6c89c3 --- /dev/null +++ b/index-tests/yarn.spec.js @@ -0,0 +1,18 @@ +import { executeBashFunction, executeBuild, doesFileExist } from "./utils"; + +test.skip("when passing -y, yarn should be used.", async () => { + const folder = "yarn"; + await executeBashFunction(`node index.js ${folder} -y`); + await executeBuild(folder); + const doesYarnLockExist = await doesFileExist(`${folder}/yarn.lock`); + expect(doesYarnLockExist).toBeTruthy(); +}); + +test.skip("When skipping installation, node_modules should not be there", async () => { + const folder = "yarn-skip"; + await executeBashFunction(`node index.js ${folder} -y -s`); + const doesNodeModulesExist = await doesFileExist(`${folder}/node_modules`); + expect(doesNodeModulesExist).toBeTruthy(); +}); + + diff --git a/index.spec.js b/index.spec.js deleted file mode 100644 index b8f18bc..0000000 --- a/index.spec.js +++ /dev/null @@ -1,35 +0,0 @@ -const { exec } = require("child_process"); - -const executeFunction = func => { - return new Promise((resolve, reject) => { - try { - func((error, output) => { - if (error) { - reject(error); - } else { - resolve(output); - } - - }); - } catch (error) { - reject(error); - } - }); -}; -const e = (command, loadingText) => { - return executeFunction(callback => exec(command, callback), loadingText); -}; -const executeBuild = folder => { - return e(`cd ${folder} && npm test && npm run webpack && npm run bundlesize`); -}; -jest.setTimeout(90000); -test("standard", async () => { - const folder = "standard"; - try { - await e(`rm -rf ${folder}`); - await e(`node index.js ${folder}`); - await executeBuild(folder); - } finally { - await e(`rm -rf ${folder}`); - } -}); diff --git a/package.json b/package.json index 126dccc..7d90b7a 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,12 @@ "scripts": { "analyze-bundle": "export ANALYZE_BUNDLE=true && npm run webpack", "start": "export NODE_ENV=development && webpack-dev-server", - "linter": "eslint index.js && eslint src --ext .js,.jsx && eslint test --ext .js,.jsx", + "linter": "eslint index.js && eslint index-tests --ext .js && eslint src --ext .js,.jsx && eslint test --ext .js,.jsx", "webpack": "export NODE_ENV=production && webpack -p --progress", "build": "babel index.js --out-file build-index.js", - "test": "npm run linter && jest --coverage", + "test": "npm run linter && npm run jest", + "pre-jest": "rm -rf yarn-skip && rm -rf yarn && rm -rf npm && rm -rf travis && rm -rf skip && rm -rf git", + "jest": "npm run pre-jest && jest --coverage && npm run pre-jest", "bundlesize": "bundlesize", "coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls", "prepublishOnly": "npm run build" diff --git a/test/client/config.js b/test/client/config.js index 1b86882..ce8adcd 100644 --- a/test/client/config.js +++ b/test/client/config.js @@ -3,3 +3,4 @@ const EnzymeAdapter = require("enzyme-adapter-react-16"); // Setup enzyme's react adapter Enzyme.configure({ adapter: new EnzymeAdapter() }); +jest.setTimeout(900000); From e03742d1189740d26beb50ba0612a4a24bad0e78 Mon Sep 17 00:00:00 2001 From: Matt Crowder Date: Tue, 12 Jun 2018 17:45:31 -0400 Subject: [PATCH 4/4] no travis --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index b03939d..42938e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,6 @@ script: - npm run webpack; - npm run coveralls; - npm run bundlesize; - - node build-index.js my-app -f; - - cd my-app; - - npm test; - - npm run webpack; - - cd ..; - ./scripts/travis-install.sh - create-react-matt hello-world -f; - cd hello-world;