Skip to content

Commit

Permalink
Run tests across all packages
Browse files Browse the repository at this point in the history
The `yarn test` tests all packages while eg. `yarn mobx test` will test
that package only.
  • Loading branch information
Daniel K committed Nov 5, 2020
1 parent a06d6cb commit 7defd13
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 152 deletions.
66 changes: 17 additions & 49 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,34 @@ orbs:
node: circleci/node@4.0.1

jobs:
mobx-build:
install:
executor: node-executor
steps:
- checkout
- node/install-packages:
pkg-manager: yarn

- run: yarn mobx build
- persist_to_workspace:
root: .
paths:
- ./*
paths: [./*]

mobx-check:
test:
executor: node-executor
steps:
- attach_workspace:
at: .
- run: yarn mobx test:check
- run: yarn lint
- run: yarn test -i
- run: yarn mobx test:types
- run: yarn mobx-react test:types

mobx-performance:
mobx:
executor: node-executor
steps:
- attach_workspace:
at: .
- run: yarn mobx build
- run: yarn mobx test:flow
- run: yarn mobx test:size
- run:
command: yarn mobx test:performance
environment:
Expand All @@ -44,47 +47,12 @@ jobs:
path: packages/mobx/perf_report
destination: mobx-perf

mobx-test:
executor: node-executor
steps:
- attach_workspace:
at: .
- run: yarn mobx test -i

mobx-size:
executor: node-executor
steps:
- attach_workspace:
at: .

- run: yarn mobx test:size

mobx-undecorate-test:
executor: node-executor
steps:
- checkout
- node/install-packages:
pkg-manager: yarn
- run: yarn mobx-undecorate test

workflows:
version: 2
mobx:
jobs:
- mobx-build
- mobx-check:
requires:
- mobx-build
- mobx-performance:
requires:
- mobx-build
- mobx-test:
requires:
- mobx-build
- mobx-size:
requires:
- mobx-build

mobx-undecorate:
test-all:
jobs:
- mobx-undecorate-test
- install
- test:
requires: [install]
- mobx:
requires: [install]
20 changes: 6 additions & 14 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module.exports = {
plugins: ["@typescript-eslint"],
extends: "eslint:recommended",
env: {
es6: true
browser: true,
es6: true,
node: true
},
parserOptions: {
ecmaVersion: 6,
Expand All @@ -18,7 +20,8 @@ module.exports = {
"no-undef": "off",
"no-extra-semi": "off", // doesn't get along well with prettier
"no-unused-vars": "off", // got typescript for that,
"no-redeclare": "off" // No idea what it does, but it dies
"no-redeclare": "off", // No idea what it does, but it dies
"require-yield": "off" // Doesn't work with TS
},
globals: {
process: "readable",
Expand All @@ -27,16 +30,5 @@ module.exports = {
setTimeout: "readable",
clearTimeout: "readable",
module: "writable"
},
overrides: [
{
files: ["**/*.ts"],
rules: {
// Things that don't play nicely with TS:
"require-yield": "off",
"no-unused-vars": "off",
"no-extra-semi": "off"
}
}
]
}
}
25 changes: 25 additions & 0 deletions jest.base.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fs = require("fs")
const path = require("path")

const tsConfig = "tsconfig.test.json"

module.exports = function buildConfig(packageDirectory, pkgConfig) {
const packageName = require(`${packageDirectory}/package.json`).name
const packageTsconfig = path.resolve(packageDirectory, tsConfig)
return {
preset: "ts-jest/presets/js-with-ts",
globals: {
__DEV__: true,
"ts-jest": {
tsconfig: fs.existsSync(packageTsconfig)
? packageTsconfig
: path.resolve(__dirname, tsConfig)
}
},
testRegex: "__tests__/.*\\.(j|t)sx?$",
coverageDirectory: "<rootDir>/coverage/",
collectCoverageFrom: ["<rootDir>/packages/*/src/**/*.{ts,tsx}"],
displayName: packageName,
...pkgConfig
}
}
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const buildConfig = require("./jest.base.config")

module.exports = buildConfig(__dirname, {
projects: ["<rootDir>/packages/*/jest.config.js"]
})
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"packages/*"
],
"scripts": {
"test": "jest",
"lint": "eslint packages/*/src/**/*",
"prettier": "prettier --write **/*.{js,ts,md}",
"release": "yarn changeset publish",
"mobx": "yarn workspace mobx",
Expand All @@ -23,7 +25,6 @@
"@types/node": "12",
"@typescript-eslint/eslint-plugin": "^4.6.1",
"@typescript-eslint/parser": "^4.1.1",
"babel-jest": "^26.6.2",
"coveralls": "^3.1.0",
"eslint": "^6.8.0",
"execa": "^4.1.0",
Expand All @@ -38,7 +39,7 @@
"pretty-quick": "3.1.0",
"serializr": "^2.0.3",
"tape": "^5.0.1",
"ts-jest": "^26.4.3",
"ts-jest": "26.4.1",
"tsdx": "^0.14.1",
"typescript": "^4.0.2"
},
Expand Down
5 changes: 0 additions & 5 deletions packages/mobx-undecorate/.gitignore

This file was deleted.

11 changes: 3 additions & 8 deletions packages/mobx-undecorate/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module.exports = {
preset: "ts-jest/presets/js-with-ts",
const buildConfig = require("../../jest.base.config")

globals: {
"ts-jest": {
tsconfig: "tsconfig.test.json"
}
},
module.exports = buildConfig(__dirname, {
testRegex: "__tests__/.*\\.spec\\.(t|j)sx?$"
}
})
8 changes: 4 additions & 4 deletions packages/mobx-undecorate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"version": "1.0.4",
"description": "Migrate MobX 4/5 to MobX 6",
"bin": "cli.js",
"scripts": {
"test": "jest"
},
"repository": {
"type": "git",
"url": "https://github.com/mobxjs/mobx.git"
Expand Down Expand Up @@ -42,5 +39,8 @@
},
"keywords": [
"mobx"
]
],
"scripts": {
"test": "jest"
}
}
3 changes: 3 additions & 0 deletions packages/mobx-undecorate/src/undecorate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ export default function transform(
}

function warn(msg: string, node: Node) {
if (process.env.NODE_ENV === "test") {
return
}
const line = lines[node.loc!.start.line - 1]
const shortline = line.replace(/^\s*/, "")
console.warn(
Expand Down
7 changes: 0 additions & 7 deletions packages/mobx-undecorate/tsconfig.test.json

This file was deleted.

15 changes: 4 additions & 11 deletions packages/mobx/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
module.exports = {
preset: "ts-jest/presets/js-with-ts",
const buildConfig = require("../../jest.base.config")

globals: {
__DEV__: true,
"ts-jest": {
tsconfig: "tsconfig.test.json"
}
},
setupFilesAfterEnv: ["<rootDir>/__tests__/setup.ts"],
module.exports = buildConfig(__dirname, {
testRegex: "__tests__/v[4|5]/base/.*\\.(t|j)sx?$",
collectCoverageFrom: ["<rootDir>/src/**/*.ts"]
}
setupFilesAfterEnv: [`<rootDir>/jest.setup.ts`]
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { configure, _resetGlobalState } from "../src/mobx"
import { configure, _resetGlobalState } from "./src/mobx"

beforeEach(() => {
// @ts-ignore
global.__DEV__ = true
_resetGlobalState()
configure({
enforceActions: "never"
Expand Down
17 changes: 8 additions & 9 deletions packages/mobx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
"react-native": "dist/mobx.esm.js",
"source": "src/mobx.ts",
"typings": "dist/mobx.d.ts",
"files": [
"src",
"dist",
"LICENSE",
"CHANGELOG.md",
"README.md"
],
"sideEffects": false,
"repository": {
"type": "git",
Expand All @@ -24,13 +31,6 @@
"bugs": {
"url": "https://github.com/mobxjs/mobx/issues"
},
"files": [
"src",
"dist",
"LICENSE",
"CHANGELOG.md",
"README.md"
],
"homepage": "https://mobx.js.org/",
"dependencies": {},
"devDependencies": {
Expand Down Expand Up @@ -65,8 +65,7 @@
"perf": "scripts/perf.sh",
"test:performance": "yarn perf proxy && yarn perf legacy",
"test:mixed-versions": "yarn test --testRegex mixed-versions",
"test:check": "yarn test:types && yarn lint",
"test:types": "tsc --noEmit && yarn test:flow",
"test:types": "tsc --noEmit",
"test:flow": "flow check",
"test:coverage": "yarn test -i --coverage",
"test:size": "yarn import-size --report . observable computed autorun action",
Expand Down
11 changes: 11 additions & 0 deletions packages/mobx/scripts/prepublish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require("fs-extra")
const path = require("path")
const execa = require("execa")

const run = () => {
fs.copySync("flow-typed/mobx.js", "dist/index.js.flow")
fs.copySync("../../README.md", "./README.md")
fs.copySync("../../LICENSE", "./LICENSE")
}

run()
8 changes: 0 additions & 8 deletions packages/mobx/tsconfig.test.json

This file was deleted.

6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"noImplicitAny": false,
"noImplicitThis": false,
"noEmit": true,
"experimentalDecorators": false,
"useDefineForClassFields": true
"experimentalDecorators": true,
"useDefineForClassFields": true,
"jsx": "react",
"esModuleInterop": true
}
}
9 changes: 2 additions & 7 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"lib": ["esnext"],
"noUnusedLocals": false,
"moduleResolution": "node",
"experimentalDecorators": true,
"useDefineForClassFields": true,
"allowSyntheticDefaultImports": true
"allowJs": true,
"noUnusedLocals": false
}
}
Loading

0 comments on commit 7defd13

Please sign in to comment.