From f8c7862c175ea2661bf6b5ef277ccd24fdf774a4 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Thu, 20 Apr 2017 21:00:58 -0700 Subject: [PATCH] WIP: stuff --- client/package-scripts.js | 10 ++ .../__tests__/__snapshots__/editor.js.snap | 2 +- package-scripts.js | 141 +++++++++++++----- package.json | 2 +- 4 files changed, 118 insertions(+), 37 deletions(-) diff --git a/client/package-scripts.js b/client/package-scripts.js index af782b51..c7efef47 100644 --- a/client/package-scripts.js +++ b/client/package-scripts.js @@ -69,6 +69,16 @@ module.exports = { script: 'jest --config=demo/unit/jest.config.json --watch', }, }, + integration: { + default: { + hiddenFromHelp, + script: 'echo "no integration demo"', + }, + watch: { + hiddenFromHelp, + script: 'echo "no integration demo"', + }, + }, }, postinstall: { hiddenFromHelp, diff --git a/client/src/screens/__tests__/__snapshots__/editor.js.snap b/client/src/screens/__tests__/__snapshots__/editor.js.snap index 5dfc3c39..4825013b 100644 --- a/client/src/screens/__tests__/__snapshots__/editor.js.snap +++ b/client/src/screens/__tests__/__snapshots__/editor.js.snap @@ -40,7 +40,7 @@ exports[`test renders editor form by default 1`] = ` data-state-key="description" data-test="description" onChange={[Function]} - placeholder="What\'s this article about?" + placeholder="What's this article about?" type="text" value="" /> diff --git a/package-scripts.js b/package-scripts.js index 5e8ce757..198c0ad7 100644 --- a/package-scripts.js +++ b/package-scripts.js @@ -13,6 +13,9 @@ const {oneLine} = commonTags const hiddenFromHelp = true +const inApi = (...scripts) => series('cd api', ...scripts, 'cd ..') +const inClient = (...scripts) => series('cd client', ...scripts, 'cd ..') + const delay = s => ifWindows(`timeout ${s}`, `sleep ${s}`) const ignoreOutput = s => `echo ${s} && ${s} ${ifWindows('> NUL', '&>/dev/null')}` @@ -58,39 +61,16 @@ module.exports = { script: 'mongo admin --eval "db.shutdownServer()"', }, }, - api: { - description: 'start the api server in production mode', - script: series('cd api', 'npm start --silent'), - test: { - hiddenFromHelp, - description: 'run the api unit and integration tests', - script: concurrent.nps('api.test.unit', 'api.test.integration'), - unit: { - hiddenFromHelp, - script: series('cd api', 'npm start test.unit --silent'), - }, - integration: { - hiddenFromHelp, - script: oneLine` - concurrently - --kill-others - --success first - --prefix "[{name}]" - --names dev.mongo,dev.api,api.test.integration - "nps dev.mongo" - "${delay(2)} && cd api && npm start --silent test.integration" - `, - }, - }, - }, + api: getApiScripts(), client: { - description: 'start the production client server', - script: series('cd client', 'npm start --silent -- "default 8080"'), - test: { - hiddenFromHelp, - description: 'run the client tests', - script: series('cd client', 'npm test --silent'), + default: { + description: 'start the production client server', + script: inClient('npm start --silent -- "default 8080"'), }, + test: getTestScripts('client'), + demo: getDemoScripts('client'), + unit: 'nps client.test.unit.watch', + integration: 'nps client.test.integration.watch', }, build: { default: { @@ -198,8 +178,7 @@ module.exports = { --exercises-dir node_modules/.tmp/client --exercises-final-dir client `, - 'nps client.test', - series('cd client', 'npm start demo', 'cd ..'), + concurrent.nps('client.test', 'client.demo'), 'nps split.client' ), }, @@ -230,8 +209,7 @@ module.exports = { --exercises-dir node_modules/.tmp/api --exercises-final-dir api `, - 'nps api.test', - series('cd api', 'npm start demo', 'cd ..'), + concurrent.nps('api.test', 'api.demo'), 'nps split.api' ), }, @@ -392,6 +370,99 @@ function getE2EScripts() { } } +function getTestScripts(dir) { + const inDir = (...scripts) => series(`cd ${dir}`, ...scripts, 'cd ..') + return { + default: { + description: `run all the ${dir} tests`, + script: concurrent.nps(`${dir}.test.unit`, `${dir}.test.integration`), + }, + unit: { + default: { + description: `run the ${dir} unit tests`, + script: inDir('npm start test.unit --silent'), + }, + watch: { + description: `run the ${dir} unit tests in watch mode`, + script: inDir('npm start test.unit.watch --silent'), + }, + }, + integration: { + default: { + description: `run the ${dir} integration tests`, + script: inDir('npm start test.integration --silent'), + }, + watch: { + description: `run the ${dir} integration tests in watch mode`, + script: inDir('npm start test.integration.watch --silent'), + }, + }, + } +} + +function getDemoScripts(dir) { + const inDir = (...scripts) => series(`cd ${dir}`, ...scripts, 'cd ..') + return { + default: { + description: `run all the ${dir} demo tests`, + script: concurrent.nps(`${dir}.demo.unit`, `${dir}.demo.integration`), + }, + unit: { + default: { + description: `run the ${dir} unit demo tests`, + script: inDir('npm start demo.unit --silent'), + }, + watch: { + description: `run the ${dir} demo unit tests in watch mode`, + script: inDir('npm start demo.unit.watch --silent'), + }, + }, + integration: { + default: { + description: `run the ${dir} integration demo tests`, + script: inDir('npm start demo.integration --silent'), + }, + watch: { + description: `run the ${dir} demo integration tests in watch mode`, + script: inDir('npm start demo.integration.watch --silent'), + }, + }, + } +} + +function getApiScripts() { + const testScripts = getTestScripts('api') + return { + default: { + description: 'start the api server in production mode', + script: inApi('npm start --silent'), + }, + test: Object.assign(testScripts, { + integration: { + default: { + description: 'Starts mongo, then starts the integration tests', + script: oneLine` + concurrently + --kill-others + --success first + --prefix "[{name}]" + --names dev.mongo,dev.api,api.test.integration + "nps dev.mongo" + " + ${delay(2)} && + ${inApi('npm start test.integration --silent')} + " + `, + }, + watch: testScripts.integration.watch, + }, + }), + demo: getDemoScripts('api'), + unit: 'nps api.test.unit.watch', + integration: 'nps api.test.integration.watch', + } +} + // this is not transpiled /* eslint diff --git a/package.json b/package.json index ecec5744..8a5142ad 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "start": "nps", "test": "nps test", - "precommit": "nps validate", + "precommit": "opt --in precommit --exec \"nps validate\"", "setup": "node ./scripts/verify && node ./scripts/install && node ./scripts/load-database && npm start validate" }, "devDependencies": {