diff --git a/.gitignore b/.gitignore index 91765f3..fefdd1f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,11 @@ bundle.js.map bundle.js index.html build -build/bundle.js.gz \ No newline at end of file +build/bundle.js.gz +standard +git +yarn +skip +npm +travis +yarn-skip \ No newline at end of file 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; 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"); } 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.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/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/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 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);