Skip to content

Commit

Permalink
Bring Jest up to the root of lerna (#145)
Browse files Browse the repository at this point in the history
Ran all tests locally to confirm they all pass since new PRs and pushes to main will only run tests affected by changes.

To run all tests in the future for other actions, we can just use `npm run test:ci`
  • Loading branch information
mattrunyon authored Aug 13, 2021
1 parent a0d38da commit 577f75b
Show file tree
Hide file tree
Showing 74 changed files with 21,814 additions and 101,320 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
fetch-depth: '0' # This action defaults to only getting the latest commit. Setting to 0 makes it retrieve the full git commit history

- name: Fetch base branch
run: |
git fetch --no-tags origin ${{ github.event.pull_request.base.ref }}
- name: Use Node.js
uses: actions/setup-node@v2
Expand Down Expand Up @@ -66,5 +72,10 @@ jobs:
- name: Build
run: npm run build

- name: Test
run: npm run test:ci
- name: Test (Pull Request)
if: ${{ github.event_name == 'pull_request' }}
run: npm run test:ci -- --changedSince origin/${{ github.event.pull_request.base.ref }}

- name: Test (Push)
if: ${{ github.event_name == 'push' }}
run: npm run test:ci -- --lastCommit
File renamed without changes.
1 change: 1 addition & 0 deletions __mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test-file-stub';
2 changes: 2 additions & 0 deletions __mocks__/monaco-editor-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// An empty mock for all the feature imports we need from monaco
// Used from the `moduleNameMapper` section in package.json
3 changes: 3 additions & 0 deletions __mocks__/monaco-editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import monaco from '../packages/mocks/monaco-editor';

module.exports = monaco;
20 changes: 12 additions & 8 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
module.exports = {
presets: ['@deephaven/babel-preset'],
ignore: [
/\.test.(tsx?|jsx?)$/,
/\.stories.(tsx?|jsx?|mdx?)$/,
'**/__mocks__/*',
'**/*.scss',
],
module.exports = api => {
const isTest = api.env('test');
return {
presets: ['@deephaven/babel-preset'],
babelrcRoots: ['.', 'packages/*'],
ignore: [
!isTest ? /\.test.(tsx?|jsx?)$/ : false,
!isTest ? '**/__mocks__/*' : false,
/\.stories.(tsx?|jsx?|mdx?)$/,
'**/*.scss',
].filter(Boolean),
};
};
7 changes: 7 additions & 0 deletions jest-runner-eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
cliOptions: {
maxWarnings: 0,
cache: true,
cacheStrategy: 'content',
},
};
25 changes: 25 additions & 0 deletions jest.config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const path = require('path');

module.exports = {
transform: {
// In CI, we don't need the tests to type check, so use babel-jest
// In non-CI (locally), use ts-jest so tests fail on type errors
'.(ts|tsx|js|jsx)': process.env.CI ? 'babel-jest' : 'ts-jest',
},
moduleNameMapper: {
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': path.join(
__dirname,
'./__mocks__/fileMock.js'
),
'^monaco-editor/esm/vs/editor/editor.api$': path.join(
__dirname,
'./__mocks__/monaco-editor.js'
),
'^monaco-editor/esm/vs/editor/(.*)': path.join(
__dirname,
'./__mocks__/monaco-editor-empty.js'
),
},
setupFilesAfterEnv: [path.join(__dirname, './jest.setup.js')],
};
24 changes: 24 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
projects: [
{
displayName: 'eslint',
runner: 'jest-runner-eslint',
testMatch: ['<rootDir>/packages/*/src/**/*.{js,jsx,ts,tsx}'],
},
{
displayName: 'stylelint',
runner: 'jest-runner-stylelint',
testMatch: ['<rootDir>/packages/*/src/**/*.scss'],
moduleFileExtensions: ['scss'],
},
'<rootDir>/packages/*/jest.config.js',
],
watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
'jest-watch-select-projects',
],
collectCoverage: false,
coverageDirectory: '<rootDir>/coverage/', // This is relative to monorepo root
collectCoverageFrom: ['./src/**/*.{js,ts,jsx,tsx}'], // This is relative to individual project root due to how Jest handles it
};
2 changes: 1 addition & 1 deletion packages/iris-grid/jest.setup.js → jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'regenerator-runtime/runtime';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { TestUtils } from '@deephaven/utils';
import '../code-studio/public/__mocks__/dh-core';
import './__mocks__/dh-core';

// disable annoying dnd-react warnings
window['__react-beautiful-dnd-disable-dev-warnings'] = true;
Expand Down
Loading

0 comments on commit 577f75b

Please sign in to comment.