Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ghost testing #2027

Merged
merged 20 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tender-news-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"modular-scripts": minor
---

Add new options for selective testing: `--ancestors`, `--changed`, `--compareBranch`
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
runs-on: ${{ matrix.os }}
env:
MODULAR_LOGGER_DEBUG: true
GIT_AUTHOR_NAME: 'Modular Tests'
GIT_AUTHOR_EMAIL: 'tests@modular.js.org'

strategy:
fail-fast: false
Expand Down
1 change: 1 addition & 0 deletions __fixtures__/ghost-testing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions __fixtures__/ghost-testing/.yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disable-self-update-check true
1 change: 1 addition & 0 deletions __fixtures__/ghost-testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the `README.md` for the whole monorepo.
5 changes: 5 additions & 0 deletions __fixtures__/ghost-testing/modular/setupTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';
56 changes: 56 additions & 0 deletions __fixtures__/ghost-testing/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "ghost-tests-monorepo",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"workspaces": [
"packages/**"
],
"modular": {
"type": "root"
},
"scripts": {
"start": "modular start",
"build": "modular build",
"test": "modular test",
"lint": "eslint . --ext .js,.ts,.tsx",
"prettier": "prettier --write ."
},
"eslintConfig": {
"extends": "modular-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"prettier": {
"singleQuote": true,
"trailingComma": "all",
"printWidth": 80,
"proseWrap": "always"
},
"dependencies": {
"@testing-library/dom": "^8.16.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^7.2.1",
"@types/jest": "^28.1.6",
"@types/node": "^18.7.2",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"eslint-config-modular-app": "^3.0.1",
"prettier": "^2.7.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": ">=4.2.1 <4.5.0"
}
}
1 change: 1 addition & 0 deletions __fixtures__/ghost-testing/packages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This will be the readme inside /packages
3 changes: 3 additions & 0 deletions __fixtures__/ghost-testing/packages/a/a-dummy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This should never be executed when testing
throw new Error('Dummy file executed for package a!');
export {};
13 changes: 13 additions & 0 deletions __fixtures__/ghost-testing/packages/a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "a",
"private": false,
"modular": {
"type": "package"
},
"main": "./src/index.ts",
"version": "1.0.0",
"dependencies": {
"b": "1.0.0",
"c": "1.0.0"
}
}
5 changes: 5 additions & 0 deletions __fixtures__/ghost-testing/packages/a/src/__tests__/a.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import add from '../index';

test('it should add two numbers', () => {
expect(add(5, 5)).toEqual(10);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import add from '../../index';

test('it should add two numbers', () => {
expect(add(3, 4)).toEqual(7);
});
4 changes: 4 additions & 0 deletions __fixtures__/ghost-testing/packages/a/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default function add(a: number, b: number): number {
//test
return a + b;
}
12 changes: 12 additions & 0 deletions __fixtures__/ghost-testing/packages/b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "b",
"private": false,
"modular": {
"type": "package"
},
"main": "./src/index.ts",
"version": "1.0.0",
"dependencies": {
"c": "1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This should never be executed when testing
throw new Error('Dummy file executed for package b!');
export {};
5 changes: 5 additions & 0 deletions __fixtures__/ghost-testing/packages/b/src/__tests__/b.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import add from '../index';

test('it should add two numbers', () => {
expect(add(1, 2)).toEqual(3);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import add from '../../index';

test('it should add two numbers', () => {
expect(add(7, 8)).toEqual(15);
});
3 changes: 3 additions & 0 deletions __fixtures__/ghost-testing/packages/b/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function add(a: number, b: number): number {
return a + b;
}
3 changes: 3 additions & 0 deletions __fixtures__/ghost-testing/packages/c/c-dummy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This should never be executed when testing
throw new Error('Dummy file executed for package c!');
export {};
12 changes: 12 additions & 0 deletions __fixtures__/ghost-testing/packages/c/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "c",
"private": false,
"modular": {
"type": "package"
},
"main": "./src/index.ts",
"version": "1.0.0",
"dependencies": {
"d": "1.0.0"
}
}
5 changes: 5 additions & 0 deletions __fixtures__/ghost-testing/packages/c/src/__tests__/c.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import add from '../index';

test('it should add two numbers', () => {
expect(add(4, 4)).toEqual(8);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import add from '../../index';

test('it should add two numbers', () => {
expect(add(7, 7)).toEqual(14);
});
3 changes: 3 additions & 0 deletions __fixtures__/ghost-testing/packages/c/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function add(a: number, b: number): number {
return a + b;
}
9 changes: 9 additions & 0 deletions __fixtures__/ghost-testing/packages/d/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "d",
"private": false,
"modular": {
"type": "package"
},
"main": "./src/index.ts",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This should never be executed when testing
throw new Error('Dummy file executed for package d!');
export {};
6 changes: 6 additions & 0 deletions __fixtures__/ghost-testing/packages/d/src/__tests__/d.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import add from '../index';

test('it should add two numbers', () => {
console.log('testing d:index.test.ts');
expect(add(87, 1)).toEqual(88);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import add from '../../index';

test('it should add two numbers', () => {
console.log('testing d:/utils/utils.test.ts');
expect(add(3, 2)).toEqual(5);
});
3 changes: 3 additions & 0 deletions __fixtures__/ghost-testing/packages/d/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function add(a: number, b: number): number {
return a + b;
}
12 changes: 12 additions & 0 deletions __fixtures__/ghost-testing/packages/e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "e",
"private": false,
"modular": {
"type": "package"
},
"main": "./src/index.ts",
"version": "1.0.0",
"dependencies": {
"a": "1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This should never be executed when testing
throw new Error('Dummy file executed for package e!');
export {};
5 changes: 5 additions & 0 deletions __fixtures__/ghost-testing/packages/e/src/__tests__/e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import add from '../index';

test('it should add two numbers', () => {
expect(add(3, 4)).toEqual(7);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import add from '../../index';

test('it should add two numbers', () => {
expect(add(15, 15)).toEqual(30);
});
3 changes: 3 additions & 0 deletions __fixtures__/ghost-testing/packages/e/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function add(a: number, b: number): number {
return a + b;
}
4 changes: 4 additions & 0 deletions __fixtures__/ghost-testing/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "modular-scripts/tsconfig.json",
"include": ["modular", "packages/**/src"]
}
25 changes: 25 additions & 0 deletions docs/commands/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ through the `jest` property in the root `package.json`
- [testRunner](#testRunner)
- [transformIgnorePatterns](#transformIgnorePatterns)

### ancestors

Default: `false`

Can be used only in combination with `changed` or the command will fail. If set,
it will additionally execute tests for all the workspaces that (directly or
indirectly) depend on the workspaces selected by `changed`.

### changed

Default: `false`

Execute tests only for the workspaces that contain files that have changed.
Files that have changed are calculated comparing the current state of the
repository with the branch specified by `compareBranch` or, if `compareBranch`
is not set, with the default git branch.

### compareBranch

Default: `undefined`

Specify the comparison branch used to determine which files have changed when
using the `changed` option. If this option is used without `changed`, the
command will fail.

#### collectCoverageFrom

[_Documentation_](https://jestjs.io/docs/configuration#collectcoveragefrom-array)
Expand Down
Loading