From 70b88de51af14791843af8baf1976d3b42d1e3b0 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 3 Jul 2018 15:49:35 -0300 Subject: [PATCH 1/5] Do not rerun relay compiler on its own changes --- config/watcher.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/watcher.ts b/config/watcher.ts index 305193045..0d3bf23c1 100644 --- a/config/watcher.ts +++ b/config/watcher.ts @@ -15,7 +15,7 @@ const config: Config = { "core/client/stream/**/*.graphql", "core/client/server/**/*.graphql", ], - ignore: ["core/**/*.d.ts"], + ignore: ["core/**/*.d.ts", "core/**/*.graphql.ts"], executor: new CommandExecutor("npm run compile:relay-stream", { runOnInit: true, }), From 9afc322314bdb8f1bc30053c9d2162773f5efeaa Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Wed, 4 Jul 2018 10:50:10 -0600 Subject: [PATCH 2/5] feat: added support for --only flag --- scripts/watcher/bin/watcher.ts | 12 ++++++++++-- scripts/watcher/types.ts | 4 ++++ scripts/watcher/watch.ts | 17 +++++++++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/scripts/watcher/bin/watcher.ts b/scripts/watcher/bin/watcher.ts index 32209c064..a3a50e6c3 100644 --- a/scripts/watcher/bin/watcher.ts +++ b/scripts/watcher/bin/watcher.ts @@ -4,16 +4,24 @@ import program from "commander"; import path from "path"; import watch from "../"; +function list(val: string) { + return val.split(","); +} + program .version("0.1.0") .usage("") + .option("-o, --only ", "only run the specified watcher", list) .arguments("") .description("Run watchers defined in ") - .action(configFile => { + .action((configFile, cmd) => { + const { only = [] } = cmd; + let config: any = require(path.resolve(configFile)); if (config.__esModule) { config = config.default; } - watch(config); + + watch(config, { only }); }) .parse(process.argv); diff --git a/scripts/watcher/types.ts b/scripts/watcher/types.ts index f78daee24..15bd6090b 100644 --- a/scripts/watcher/types.ts +++ b/scripts/watcher/types.ts @@ -17,6 +17,10 @@ export interface Executor { execute(filePath: string): void; } +export interface Options { + only?: string[]; +} + export interface Config { rootDir?: string; backend?: Watcher; diff --git a/scripts/watcher/watch.ts b/scripts/watcher/watch.ts index 572f7107b..8a3feac75 100644 --- a/scripts/watcher/watch.ts +++ b/scripts/watcher/watch.ts @@ -2,7 +2,7 @@ import Joi from "joi"; import path from "path"; import ChokidarWatcher from "./ChokidarWatcher"; -import { Config, configSchema, WatchConfig, Watcher } from "./types"; +import { Config, configSchema, Options, WatchConfig, Watcher } from "./types"; // Polyfill the asyncIterator symbol. if (Symbol.asyncIterator === undefined) { @@ -43,9 +43,22 @@ function setupCleanup(config: Config) { ); } -export default async function watch(config: Config) { +function filterOnly(config: Config, only: string[]) { + for (const key of Object.keys(config.watchers)) { + if (only.indexOf(key) === -1) { + // tslint:disable-next-line:no-console + console.log(`Disabled watcher "${key}"`); + delete config.watchers[key]; + } + } +} + +export default async function watch(config: Config, options?: Options) { Joi.assert(config, configSchema); const watcher = config.backend || new ChokidarWatcher(); + if (options && options.only && options.only.length > 0) { + filterOnly(config, options.only); + } setupCleanup(config); for (const key of Object.keys(config.watchers)) { // tslint:disable-next-line:no-console From 1a14c131051dde2572b95e63f57ebca1b8a23617 Mon Sep 17 00:00:00 2001 From: Kiwi Date: Wed, 4 Jul 2018 14:01:08 -0300 Subject: [PATCH 3/5] Use JSDocs comments (#1727) --- scripts/watcher/CommandExecutor.ts | 6 +++--- scripts/watcher/LongRunningExecutor.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/watcher/CommandExecutor.ts b/scripts/watcher/CommandExecutor.ts index 60cf15e6a..fddba0b8b 100644 --- a/scripts/watcher/CommandExecutor.ts +++ b/scripts/watcher/CommandExecutor.ts @@ -5,13 +5,13 @@ import { Executor } from "./types"; interface CommandExecutorOptions { args?: ReadonlyArray; - // If true, allow spawning multiple processes. + /** If true, allow spawning multiple processes. */ spawnMutiple?: boolean; - // Specify the period in which the process is started at max once. + /** Specify the period in which the process is started at max once. */ debounce?: number | false; - // If true, will run command upon initialization. + /** If true, will run command upon initialization. */ runOnInit?: boolean; } diff --git a/scripts/watcher/LongRunningExecutor.ts b/scripts/watcher/LongRunningExecutor.ts index cffe6f7db..7019c1fb3 100644 --- a/scripts/watcher/LongRunningExecutor.ts +++ b/scripts/watcher/LongRunningExecutor.ts @@ -6,7 +6,7 @@ import { Executor } from "./types"; interface LongRunningExecutorOptions { args?: ReadonlyArray; - // Specify the period in which the process is restarted at max once. + /** Specify the period in which the process is restarted at max once. */ debounce?: number; } From c9c99623bc50820a308697fe224711643784628f Mon Sep 17 00:00:00 2001 From: Kiwi Date: Wed, 4 Jul 2018 14:12:43 -0300 Subject: [PATCH 4/5] [next] Remove nodemon (#1725) * Remove old nodemon configs * Remove nodemon --- config/nodemon/relay-stream.json | 8 ---- config/nodemon/server.json | 10 ----- package-lock.json | 77 -------------------------------- package.json | 3 +- 4 files changed, 1 insertion(+), 97 deletions(-) delete mode 100644 config/nodemon/relay-stream.json delete mode 100644 config/nodemon/server.json diff --git a/config/nodemon/relay-stream.json b/config/nodemon/relay-stream.json deleted file mode 100644 index dc9556823..000000000 --- a/config/nodemon/relay-stream.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "exec": "npm-run-all compile:relay-stream", - "ext": "ts,tsx,graphql", - "watch": [ - "./src/core/client/stream", - "./src/core/**/*.graphql" - ] -} diff --git a/config/nodemon/server.json b/config/nodemon/server.json deleted file mode 100644 index 08472086e..000000000 --- a/config/nodemon/server.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "exec": "npm run start:development", - "ext": "ts,graphql", - "watch": [ - "./src" - ], - "ignore": [ - "./src/client" - ] -} diff --git a/package-lock.json b/package-lock.json index b3622a48d..6038504da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9820,12 +9820,6 @@ "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==", "dev": true }, - "ignore-by-default": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", - "integrity": "sha1-SMptcvbGo68Aqa1K5odr44ieKwk=", - "dev": true - }, "immutable": { "version": "3.7.6", "resolved": "https://registry.npmjs.org/immutable/-/immutable-3.7.6.tgz", @@ -12790,50 +12784,6 @@ "which": "^1.3.0" } }, - "nodemon": { - "version": "1.17.5", - "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-1.17.5.tgz", - "integrity": "sha512-FG2mWJU1Y58a9ktgMJ/RZpsiPz3b7ge77t/okZHEa4NbrlXGKZ8s1A6Q+C7+JPXohAfcPALRwvxcAn8S874pmw==", - "dev": true, - "requires": { - "chokidar": "^2.0.2", - "debug": "^3.1.0", - "ignore-by-default": "^1.0.1", - "minimatch": "^3.0.4", - "pstree.remy": "^1.1.0", - "semver": "^5.5.0", - "supports-color": "^5.2.0", - "touch": "^3.1.0", - "undefsafe": "^2.0.2", - "update-notifier": "^2.3.0" - }, - "dependencies": { - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true - }, - "supports-color": { - "version": "5.4.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", - "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - } - } - }, "nopt": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz", @@ -15936,15 +15886,6 @@ "integrity": "sha512-+AqO1Ae+N/4r7Rvchrdm432afjT9hqJRyBN3DQv9At0tPz4hIFSGKbq64fN9dVoCow4oggIIax5/iONx0r9hZw==", "dev": true }, - "pstree.remy": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.0.tgz", - "integrity": "sha512-q5I5vLRMVtdWa8n/3UEzZX7Lfghzrg9eG2IKk2ENLSofKRCXVqMvMUHxCKgXNaqH/8ebhBxrqftHWnyTFweJ5Q==", - "dev": true, - "requires": { - "ps-tree": "^1.1.0" - } - }, "public-encrypt": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/public-encrypt/-/public-encrypt-4.0.2.tgz", @@ -18801,15 +18742,6 @@ "integrity": "sha1-LmhELZ9k7HILjMieZEOsbKqVACk=", "dev": true }, - "touch": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz", - "integrity": "sha512-WBx8Uy5TLtOSRtIq+M03/sKDrXCLHxwDcquSP2c43Le03/9serjQBIztjRz6FkJez9D/hleyAXTBGLwwZUw9lA==", - "dev": true, - "requires": { - "nopt": "~1.0.10" - } - }, "tough-cookie": { "version": "2.4.3", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", @@ -19684,15 +19616,6 @@ "integrity": "sha512-keqHubrlpvT6G2wH0OEfSW4mquYRcbe/J8NMmveoQOjUqmo+hXtO+ORCpWhdbZ7k72UtY61BL7haGxW6enBnjw==", "dev": true }, - "undefsafe": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.2.tgz", - "integrity": "sha1-Il9rngM3Zj4Njnz9aG/Cg2zKznY=", - "dev": true, - "requires": { - "debug": "^2.2.0" - } - }, "unherit": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/unherit/-/unherit-1.1.1.tgz", diff --git a/package.json b/package.json index 5f615b41f..707d65836 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,6 @@ "html-webpack-plugin": "^3.2.0", "jest": "^23.2.0", "loader-utils": "^1.1.0", - "nodemon": "^1.17.5", "npm-run-all": "^4.1.3", "postcss-flexbugs-fixes": "^3.3.1", "postcss-font-magician": "^2.2.1", @@ -141,4 +140,4 @@ "webpack-hot-client": "^4.0.3", "webpack-manifest-plugin": "^2.0.3" } -} \ No newline at end of file +} From 37cb23dd59b47f0e4a9b1b2830b9292f2b018f4d Mon Sep 17 00:00:00 2001 From: Kiwi Date: Thu, 5 Jul 2018 12:04:38 -0300 Subject: [PATCH 5/5] [next] Jest implementation for React Components (#1733) * Make jest testing work with custom path and css modules * Add first test * feat: added unit tests to ci * fix: updated package-lock.json * Update cssTransform.js * Update cssTransform.js * Fix test in ci --- .circleci/config.yml | 17 ++ config/jest.config.js | 9 +- config/jest/cssTransform.js | 96 +++++++- package-lock.json | 229 ++++++++++-------- package.json | 9 +- scripts/test.js | 2 +- .../client/stream/components/Comment.spec.tsx | 28 +++ .../__snapshots__/Comment.spec.tsx.snap | 33 +++ 8 files changed, 308 insertions(+), 115 deletions(-) create mode 100644 src/core/client/stream/components/Comment.spec.tsx create mode 100644 src/core/client/stream/components/__snapshots__/Comment.spec.tsx.snap diff --git a/.circleci/config.yml b/.circleci/config.yml index 908210e13..bd7493f6b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -43,6 +43,20 @@ jobs: name: Perform linting command: npm run lint + # unit_tests will run the unit tests. + unit_tests: + <<: *job_defaults + steps: + - checkout + - attach_workspace: + at: ~/coralproject/talk + - run: + name: Compile schemas and types + command: npm run compile + - run: + name: Perform testing + command: npm run test + # build will build the static assets and server typescript files. build: <<: *job_defaults @@ -74,6 +88,9 @@ workflows: - lint: requires: - npm_dependencies + - unit_tests: + requires: + - npm_dependencies - build: requires: - npm_dependencies diff --git a/config/jest.config.js b/config/jest.config.js index 682a2c8a4..ed9b641ae 100644 --- a/config/jest.config.js +++ b/config/jest.config.js @@ -8,7 +8,7 @@ module.exports = { setupFiles: ["/config/polyfills.js"], testMatch: [ "**/__tests__/**/*.{js,jsx,mjs,ts,tsx}", - "**/*.(spec|test).{js,jsx,mjs,ts,tsx}", + "**/*.spec.{js,jsx,mjs,ts,tsx}", ], testEnvironment: "node", testURL: "http://localhost", @@ -22,7 +22,12 @@ module.exports = { "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$", ], moduleNameMapper: { - "^react-native$": "react-native-web", + "^talk-admin/(.*)$": "/src/core/client/admin/$1", + "^talk-ui/(.*)$": "/src/core/client/ui/$1", + "^talk-stream/(.*)$": "/src/core/client/stream/$1", + "^talk-framework/(.*)$": "/src/core/client/framework/$1", + "^talk-common/(.*)$": "/src/core/common/$1", + "^talk-server/(.*)$": "/src/core/server/$1", }, moduleFileExtensions: [ "web.js", diff --git a/config/jest/cssTransform.js b/config/jest/cssTransform.js index 606cc276b..90b6bfa63 100644 --- a/config/jest/cssTransform.js +++ b/config/jest/cssTransform.js @@ -1,14 +1,94 @@ "use strict"; -// This is a custom Jest transformer turning style imports into empty objects. -// http://facebook.github.io/jest/docs/en/webpack.html +// Adapted version of https://github.com/Connormiha/jest-css-modules-transform +// Copyright https://github.com/Connormiha/jest-css-modules-transform/graphs/contributors +// This oututs `module.exports = cssObject` instead of `module.exports = { default: cssObject }`; + +const { sep: pathSep, resolve } = require("path"); +const postcss = require("postcss"); +const postcssNested = postcss([require("postcss-nested")]); + +const REG_EXP_NAME_BREAK_CHAR = /[\s,.{/#[:]/; + +const getCSSSelectors = (css, path) => { + const end = css.length; + let i = 0; + let char; + let bracketsCount = 0; + const result = {}; + + while (i < end) { + if (i === -1) { + throw Error(`Parse error ${path}`); + } + if (css.indexOf("/*", i) === i) { + i = css.indexOf("*/", i + 2); + // Unclosed comment. Break to avoid infinity loop + if (i === -1) { + // Don't parse, but save collected result + return result; + } + continue; + } + char = css[i]; + if (char === "{") { + bracketsCount++; + i++; + continue; + } + if (char === "}") { + bracketsCount--; + i++; + continue; + } + if (char === '"' || char === "'") { + do { + i = css.indexOf(char, i + 1); + // Syntax error since this line. Don't parse, but save collected result + if (i === -1) { + return result; + } + } while (css[i - 1] === "\\"); + i++; + continue; + } + if (bracketsCount > 0) { + i++; + continue; + } + if (char === "." || char === "#") { + i++; + const startWord = i; + while (!REG_EXP_NAME_BREAK_CHAR.test(css[i])) { + i++; + } + const word = css.slice(startWord, i); + result[word] = word; + continue; + } + if (css.indexOf("@keyframes", i) === i) { + i += 10; + while (REG_EXP_NAME_BREAK_CHAR.test(css[i])) { + i++; + } + const startWord = i; + while (!REG_EXP_NAME_BREAK_CHAR.test(css[i])) { + i++; + } + const word = css.slice(startWord, i); + result[word] = word; + continue; + } + i++; + } + return result; +}; module.exports = { - process() { - return "module.exports = {};"; - }, - getCacheKey() { - // The output is always the same. - return "cssTransform"; + process(src, path, config) { + const filename = path.slice(path.lastIndexOf(pathSep) + 1); + const textCSS = postcssNested.process(src).css; + const exprt = JSON.stringify(getCSSSelectors(textCSS, path)); + return `module.exports = ${exprt}`; }, }; diff --git a/package-lock.json b/package-lock.json index 6038504da..c6dd91c93 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1628,13 +1628,17 @@ } }, "@types/react-relay": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@types/react-relay/-/react-relay-1.3.6.tgz", - "integrity": "sha512-X0qv3nGlE4TStFLLKxgj+6MgHZEExB1N/RDcVcyCauAojV5byD0c6VhuqAluYaTKaL2FBuxdtDL405IhIIjEbQ==", + "version": "github:coralproject/patched#ba4c8d01bb737e5f073534b32d870294e39cc5a8", + "from": "github:coralproject/patched#types/react-relay", + "dev": true + }, + "@types/react-test-renderer": { + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/@types/react-test-renderer/-/react-test-renderer-16.0.1.tgz", + "integrity": "sha512-kmNh8g67Ck/y/vp6KX+4JTJXiTGLZBylNhu+R7sm7zcvsrnIGVO6J1zew5inVg428j9f8yHpl68RcYOZXVborQ==", "dev": true, "requires": { - "@types/react": "*", - "@types/relay-runtime": "*" + "@types/react": "*" } }, "@types/recompose": { @@ -7635,17 +7639,17 @@ } }, "expect": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/expect/-/expect-23.2.0.tgz", - "integrity": "sha1-U6fhNeNv4n51hnsReP8IqqzCsN0=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/expect/-/expect-23.3.0.tgz", + "integrity": "sha1-7LBRrcvcQKxNtXbBYGfxL9sTzGE=", "dev": true, "requires": { "ansi-styles": "^3.2.0", "jest-diff": "^23.2.0", "jest-get-type": "^22.1.0", "jest-matcher-utils": "^23.2.0", - "jest-message-util": "^23.2.0", - "jest-regex-util": "^23.0.0" + "jest-message-util": "^23.3.0", + "jest-regex-util": "^23.3.0" }, "dependencies": { "ansi-styles": { @@ -10835,13 +10839,13 @@ "dev": true }, "jest": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/jest/-/jest-23.2.0.tgz", - "integrity": "sha1-govzGgltRdzwaCTR6gMBOve8/CA=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest/-/jest-23.3.0.tgz", + "integrity": "sha1-E1XNeS84zyD7pNoC3dt8oU2UhLU=", "dev": true, "requires": { "import-local": "^1.0.0", - "jest-cli": "^23.2.0" + "jest-cli": "^23.3.0" }, "dependencies": { "ansi-regex": { @@ -10865,9 +10869,9 @@ } }, "jest-cli": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-23.2.0.tgz", - "integrity": "sha1-O1Q6PaUUXdiTeTEBcoI3n8aWxFs=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-23.3.0.tgz", + "integrity": "sha1-MH6b53M0Q7eJqCedaUBU0FGp5eI=", "dev": true, "requires": { "ansi-escapes": "^3.0.0", @@ -10882,18 +10886,18 @@ "istanbul-lib-instrument": "^1.10.1", "istanbul-lib-source-maps": "^1.2.4", "jest-changed-files": "^23.2.0", - "jest-config": "^23.2.0", - "jest-environment-jsdom": "^23.2.0", + "jest-config": "^23.3.0", + "jest-environment-jsdom": "^23.3.0", "jest-get-type": "^22.1.0", "jest-haste-map": "^23.2.0", - "jest-message-util": "^23.2.0", - "jest-regex-util": "^23.0.0", - "jest-resolve-dependencies": "^23.2.0", - "jest-runner": "^23.2.0", - "jest-runtime": "^23.2.0", - "jest-snapshot": "^23.2.0", - "jest-util": "^23.2.0", - "jest-validate": "^23.2.0", + "jest-message-util": "^23.3.0", + "jest-regex-util": "^23.3.0", + "jest-resolve-dependencies": "^23.3.0", + "jest-runner": "^23.3.0", + "jest-runtime": "^23.3.0", + "jest-snapshot": "^23.3.0", + "jest-util": "^23.3.0", + "jest-validate": "^23.3.0", "jest-watcher": "^23.2.0", "jest-worker": "^23.2.0", "micromatch": "^3.1.10", @@ -10938,23 +10942,23 @@ } }, "jest-config": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-23.2.0.tgz", - "integrity": "sha1-0vtVb9WioZw561bROdzKXa0qHIg=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-23.3.0.tgz", + "integrity": "sha1-u01Ttw+VAPr933GNImq7U7E7gyM=", "dev": true, "requires": { "babel-core": "^6.0.0", "babel-jest": "^23.2.0", "chalk": "^2.0.1", "glob": "^7.1.1", - "jest-environment-jsdom": "^23.2.0", - "jest-environment-node": "^23.2.0", + "jest-environment-jsdom": "^23.3.0", + "jest-environment-node": "^23.3.0", "jest-get-type": "^22.1.0", - "jest-jasmine2": "^23.2.0", - "jest-regex-util": "^23.0.0", + "jest-jasmine2": "^23.3.0", + "jest-regex-util": "^23.3.0", "jest-resolve": "^23.2.0", - "jest-util": "^23.2.0", - "jest-validate": "^23.2.0", + "jest-util": "^23.3.0", + "jest-validate": "^23.3.0", "pretty-format": "^23.2.0" }, "dependencies": { @@ -11003,24 +11007,24 @@ } }, "jest-environment-jsdom": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/jest-environment-jsdom/-/jest-environment-jsdom-23.2.0.tgz", - "integrity": "sha1-NjRgOgipdbDKimWDIPVqVKjgRVg=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest-environment-jsdom/-/jest-environment-jsdom-23.3.0.tgz", + "integrity": "sha1-GQRX+RyeYVRUxBhgVgZdtu16Tio=", "dev": true, "requires": { "jest-mock": "^23.2.0", - "jest-util": "^23.2.0", + "jest-util": "^23.3.0", "jsdom": "^11.5.1" } }, "jest-environment-node": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-23.2.0.tgz", - "integrity": "sha1-tv5BNy44IJO7bz2b32wcTsClDxg=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-23.3.0.tgz", + "integrity": "sha1-Ho3yHIR6pdA7dlc/DcFvzeUDTDI=", "dev": true, "requires": { "jest-mock": "^23.2.0", - "jest-util": "^23.2.0" + "jest-util": "^23.3.0" } }, "jest-get-type": { @@ -11056,21 +11060,21 @@ } }, "jest-jasmine2": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-23.2.0.tgz", - "integrity": "sha1-qmcM2x5NX47HdMlN2l4QX+M9i7Q=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-23.3.0.tgz", + "integrity": "sha1-qHBrqsI8ihMNWqjvVGSp1JCW0bU=", "dev": true, "requires": { "chalk": "^2.0.1", "co": "^4.6.0", - "expect": "^23.2.0", + "expect": "^23.3.0", "is-generator-fn": "^1.0.0", "jest-diff": "^23.2.0", "jest-each": "^23.2.0", "jest-matcher-utils": "^23.2.0", - "jest-message-util": "^23.2.0", - "jest-snapshot": "^23.2.0", - "jest-util": "^23.2.0", + "jest-message-util": "^23.3.0", + "jest-snapshot": "^23.3.0", + "jest-util": "^23.3.0", "pretty-format": "^23.2.0" } }, @@ -11095,9 +11099,9 @@ } }, "jest-message-util": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-23.2.0.tgz", - "integrity": "sha1-WR6BSP/2nPibBBSAnHIXVuvv50Q=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-23.3.0.tgz", + "integrity": "sha1-vAexHOxpcftd2d4t+2DrwiFQwWA=", "dev": true, "requires": { "@babel/code-frame": "^7.0.0-beta.35", @@ -11114,9 +11118,9 @@ "dev": true }, "jest-regex-util": { - "version": "23.0.0", - "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-23.0.0.tgz", - "integrity": "sha1-3Vwf3gxG9DcTFM8Q96dRoj9Oj3Y=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-23.3.0.tgz", + "integrity": "sha1-X4ZylUfCeFxAAs6qj4Sf6MpHG8U=", "dev": true }, "jest-resolve": { @@ -11131,31 +11135,31 @@ } }, "jest-resolve-dependencies": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-23.2.0.tgz", - "integrity": "sha1-bfjVcJxkBmOc0H9Uv/B04BtcBFg=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-23.3.0.tgz", + "integrity": "sha1-hETTsLEoi4CGTYgB/1C0Sk1pXR0=", "dev": true, "requires": { - "jest-regex-util": "^23.0.0", - "jest-snapshot": "^23.2.0" + "jest-regex-util": "^23.3.0", + "jest-snapshot": "^23.3.0" } }, "jest-runner": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-23.2.0.tgz", - "integrity": "sha1-DZGWfqgvcrDHBZEJJghtIFXOda8=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-23.3.0.tgz", + "integrity": "sha1-BMfkWKYXUBpIddsNf/vg48vUO/s=", "dev": true, "requires": { "exit": "^0.1.2", "graceful-fs": "^4.1.11", - "jest-config": "^23.2.0", + "jest-config": "^23.3.0", "jest-docblock": "^23.2.0", "jest-haste-map": "^23.2.0", - "jest-jasmine2": "^23.2.0", + "jest-jasmine2": "^23.3.0", "jest-leak-detector": "^23.2.0", - "jest-message-util": "^23.2.0", - "jest-runtime": "^23.2.0", - "jest-util": "^23.2.0", + "jest-message-util": "^23.3.0", + "jest-runtime": "^23.3.0", + "jest-util": "^23.3.0", "jest-worker": "^23.2.0", "source-map-support": "^0.5.6", "throat": "^4.0.0" @@ -11173,9 +11177,9 @@ } }, "jest-runtime": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-23.2.0.tgz", - "integrity": "sha1-YtywF2ahxMZGltwJAgnnbOGq3Lw=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-23.3.0.tgz", + "integrity": "sha1-SGWqtM7/gvnOxjNf164UIswd598=", "dev": true, "requires": { "babel-core": "^6.0.0", @@ -11185,14 +11189,14 @@ "exit": "^0.1.2", "fast-json-stable-stringify": "^2.0.0", "graceful-fs": "^4.1.11", - "jest-config": "^23.2.0", + "jest-config": "^23.3.0", "jest-haste-map": "^23.2.0", - "jest-message-util": "^23.2.0", - "jest-regex-util": "^23.0.0", + "jest-message-util": "^23.3.0", + "jest-regex-util": "^23.3.0", "jest-resolve": "^23.2.0", - "jest-snapshot": "^23.2.0", - "jest-util": "^23.2.0", - "jest-validate": "^23.2.0", + "jest-snapshot": "^23.3.0", + "jest-util": "^23.3.0", + "jest-validate": "^23.3.0", "micromatch": "^3.1.10", "realpath-native": "^1.0.0", "slash": "^1.0.0", @@ -11208,30 +11212,35 @@ "dev": true }, "jest-snapshot": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-23.2.0.tgz", - "integrity": "sha1-x6PQFxd7utYMillYac+QqHguan4=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-23.3.0.tgz", + "integrity": "sha1-/E6fgeRUMtEFB+J/ULzmD0TYFCQ=", "dev": true, "requires": { + "babel-traverse": "^6.0.0", + "babel-types": "^6.0.0", "chalk": "^2.0.1", "jest-diff": "^23.2.0", "jest-matcher-utils": "^23.2.0", + "jest-message-util": "^23.3.0", + "jest-resolve": "^23.2.0", "mkdirp": "^0.5.1", "natural-compare": "^1.4.0", - "pretty-format": "^23.2.0" + "pretty-format": "^23.2.0", + "semver": "^5.5.0" } }, "jest-util": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-23.2.0.tgz", - "integrity": "sha1-YrdwdXaW2W4JSgS48cNzylClqy4=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-23.3.0.tgz", + "integrity": "sha1-efNbsMMBAO9hHZY+5riPjthzqB0=", "dev": true, "requires": { "callsites": "^2.0.0", "chalk": "^2.0.1", "graceful-fs": "^4.1.11", "is-ci": "^1.0.10", - "jest-message-util": "^23.2.0", + "jest-message-util": "^23.3.0", "mkdirp": "^0.5.1", "slash": "^1.0.0", "source-map": "^0.6.0" @@ -11246,9 +11255,9 @@ } }, "jest-validate": { - "version": "23.2.0", - "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-23.2.0.tgz", - "integrity": "sha1-Z8i5CeEa8XAXZSOIlMZ6wykbGV4=", + "version": "23.3.0", + "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-23.3.0.tgz", + "integrity": "sha1-1Jvqaq2YwwrNLLtUJDR5igzBP3Y=", "dev": true, "requires": { "chalk": "^2.0.1", @@ -15831,13 +15840,13 @@ "dev": true }, "prompts": { - "version": "0.1.9", - "resolved": "https://registry.npmjs.org/prompts/-/prompts-0.1.9.tgz", - "integrity": "sha512-RMRvwAUDVUMhP/z3YfDW6igMwT0UnL+w3XCUUNxxHjgwJnVEdHWYJVjM7hQMPub8HCk12xZYAqWlbgLBnqebwg==", + "version": "0.1.10", + "resolved": "https://registry.npmjs.org/prompts/-/prompts-0.1.10.tgz", + "integrity": "sha512-/MPwms6+g/m6fvXZlQyOL4m4ziDim2+Wc6CdWVjp+nVCkzEkK2N4rR74m/bbGf+dkta+/SBpo1FfES8Wgrk/Fw==", "dev": true, "requires": { - "clorox": "^1.0.1", - "sisteransi": "^0.1.0" + "clorox": "^1.0.3", + "sisteransi": "^0.1.1" } }, "prop-types": { @@ -16360,6 +16369,12 @@ "shallowequal": "^1.0.2" } }, + "react-is": { + "version": "16.4.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.4.1.tgz", + "integrity": "sha512-xpb0PpALlFWNw/q13A+1aHeyJyLYCg0/cCHPUA43zYluZuIPHaHL3k8OBsTgQtxqW0FhyDEMvi8fZ/+7+r4OSQ==", + "dev": true + }, "react-lifecycles-compat": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz", @@ -16460,6 +16475,18 @@ } } }, + "react-test-renderer": { + "version": "16.4.1", + "resolved": "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-16.4.1.tgz", + "integrity": "sha512-wyyiPxRZOTpKnNIgUBOB6xPLTpIzwcQMIURhZvzUqZzezvHjaGNsDPBhMac5fIY3Jf5NuKxoGvV64zDSOECPPQ==", + "dev": true, + "requires": { + "fbjs": "^0.8.16", + "object-assign": "^4.1.1", + "prop-types": "^15.6.0", + "react-is": "^16.4.1" + } + }, "read-pkg": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-3.0.0.tgz", @@ -16509,9 +16536,9 @@ } }, "realpath-native": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/realpath-native/-/realpath-native-1.0.0.tgz", - "integrity": "sha512-XJtlRJ9jf0E1H1SLeJyQ9PGzQD7S65h1pRXEcAeK48doKOnKxcgPeNohJvD5u/2sI9J1oke6E8bZHS/fmW1UiQ==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/realpath-native/-/realpath-native-1.0.1.tgz", + "integrity": "sha512-W14EcXuqUvKP8dkWkD7B95iMy77lpMnlFXbbk409bQtNCbeu0kvRE5reo+yIZ3JXxg6frbGsz2DLQ39lrCB40g==", "dev": true, "requires": { "util.promisify": "^1.0.0" @@ -17755,9 +17782,9 @@ } }, "sisteransi": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-0.1.0.tgz", - "integrity": "sha512-kHXcIr0Z9FM6d7pwFDDIMQKGndIEtIF1oBSMXWtItpx4mrH1jhANVNT35GVekBekXl6J+5i7lJMIGq3Gm7pIdA==", + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-0.1.1.tgz", + "integrity": "sha512-PmGOd02bM9YO5ifxpw36nrNMBTptEtfRl4qUYl9SndkolplkrZZOW7PGHjrZL53QvMVj9nQ+TKqUnRsw4tJa4g==", "dev": true }, "slash": { diff --git a/package.json b/package.json index 707d65836..820605d35 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,11 @@ "scripts": { "start": "node dist/index.js", "test": "node scripts/test.js --env=jsdom", - "build": "npm-run-all --parallel compile:* && npm-run-all --parallel build:*", + "build": "npm-run-all compile --parallel build:*", "build:client": "node ./scripts/build.js", "build:server": "tsc -p ./src/tsconfig.json", "watch": "NODE_ENV=development ts-node ./scripts/watcher/bin/watcher.ts ./config/watcher.ts", + "compile": "npm-run-all --parallel compile:*", "compile:css-types": "tcm src/core/client/", "compile:relay-stream": "relay-compiler --src ./src/core/client/stream --schema $(ts-node ./scripts/schemaPath.ts tenant) --language typescript --artifactDirectory ./src/core/client/stream/__generated__ --no-watchman", "start:development": "NODE_ENV=development ts-node --project ./src/tsconfig.json -r tsconfig-paths/register ./src/index.ts", @@ -72,7 +73,8 @@ "@types/passport": "^0.4.5", "@types/query-string": "^6.1.0", "@types/react-dom": "^16.0.6", - "@types/react-relay": "^1.3.6", + "@types/react-relay": "github:coralproject/patched#types/react-relay", + "@types/react-test-renderer": "^16.0.1", "@types/recompose": "^0.26.1", "@types/relay-runtime": "github:coralproject/patched#types/relay-runtime", "@types/uuid": "^3.4.3", @@ -100,7 +102,7 @@ "fluent-react": "^0.7.0", "graphql-playground-middleware-express": "^1.7.0", "html-webpack-plugin": "^3.2.0", - "jest": "^23.2.0", + "jest": "^23.3.0", "loader-utils": "^1.1.0", "npm-run-all": "^4.1.3", "postcss-flexbugs-fixes": "^3.3.1", @@ -115,6 +117,7 @@ "react-dom": "^16.4.0", "react-final-form": "^3.6.0", "react-relay": "github:coralproject/patched#react-relay", + "react-test-renderer": "^16.4.1", "recompose": "^0.27.1", "relay-compiler": "github:coralproject/patched#relay-compiler", "relay-compiler-language-typescript": "github:coralproject/patched#relay-compiler-language-typescript", diff --git a/scripts/test.js b/scripts/test.js index 1ac08fd2e..f08b18de6 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -19,11 +19,11 @@ const paths = require("../config/paths"); const jest = require("jest"); let argv = process.argv.slice(2); +argv.push("--config", paths.appJestConfig); // Watch unless on CI or in coverage mode if (!process.env.CI && argv.indexOf("--coverage") < 0) { argv.push("--watch"); - argv.push("--config", paths.appJestConfig); } jest.run(argv); diff --git a/src/core/client/stream/components/Comment.spec.tsx b/src/core/client/stream/components/Comment.spec.tsx new file mode 100644 index 000000000..6008bfc3b --- /dev/null +++ b/src/core/client/stream/components/Comment.spec.tsx @@ -0,0 +1,28 @@ +import React from "react"; +import { createRenderer } from "react-test-renderer/shallow"; +import Comment from "./Comment"; + +it("renders username and body", () => { + const props = { + author: { + username: "Marvin", + }, + body: "Woof", + }; + const renderer = createRenderer(); + renderer.render(); + expect(renderer.getRenderOutput()).toMatchSnapshot(); +}); + +it("renders with gutterBottom", () => { + const props = { + author: { + username: "Marvin", + }, + body: "Woof", + gutterBottom: true, + }; + const renderer = createRenderer(); + renderer.render(); + expect(renderer.getRenderOutput()).toMatchSnapshot(); +}); diff --git a/src/core/client/stream/components/__snapshots__/Comment.spec.tsx.snap b/src/core/client/stream/components/__snapshots__/Comment.spec.tsx.snap new file mode 100644 index 000000000..4b009e257 --- /dev/null +++ b/src/core/client/stream/components/__snapshots__/Comment.spec.tsx.snap @@ -0,0 +1,33 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders username and body 1`] = ` +
+ + Marvin + + + Woof + +
+`; + +exports[`renders with gutterBottom 1`] = ` +
+ + Marvin + + + Woof + +
+`;