diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 000000000..120b1d53e --- /dev/null +++ b/jest.config.js @@ -0,0 +1,16 @@ +/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +const sharedConfig = require('./script/test/jest.base.js'); + +module.exports = { + ...sharedConfig, + clearMocks: true, + verbose: false, + + setupFilesAfterEnv: ['./script/test/jest-setup.ts'], + projects: ['/packages/zapp/console', '/packages/plugins/components'], + + coverageDirectory: '/.coverage', + collectCoverageFrom: ['**/*.{ts,tsx}', '!**/*/*.stories.{ts,tsx}', '!**/*/*.mocks.{ts,tsx}'], + coveragePathIgnorePatterns: [...sharedConfig.coveragePathIgnorePatterns], + coverageReporters: ['text', 'json', 'html'], +}; diff --git a/package.json b/package.json index ec266dedc..a747f7593 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,9 @@ "build:storybook": "build-storybook", "lint": "eslint . --ext .js,.jsx,.ts,.tsx", "storybook": "start-storybook -p 6006", - "test": "cd packages/zapp/console && yarn test && cd ../../../", - "test-coverage": "bash -c 'pushd packages/zapp/console && yarn test-coverage && popd'" + "test": "NODE_ENV=test jest", + "test:clear": "jest --clearCache", + "test-coverage": "NODE_ENV=test jest --coverage" }, "husky": { "hooks": { @@ -54,6 +55,11 @@ "@storybook/manager-webpack5": "^6.4.19", "@storybook/react": "^6.4.19", "@storybook/testing-library": "^0.0.9", + "@testing-library/jest-dom": "^5.5.0", + "@testing-library/react": "^10.0.3", + "@testing-library/react-hooks": "^7.0.2", + "ts-jest": "^26.3.0", + "jest": "^26.0.0", "react-hot-loader": "^4.1.2" } } diff --git a/packages/plugins/components/jest.config.js b/packages/plugins/components/jest.config.js new file mode 100644 index 000000000..ecb112b22 --- /dev/null +++ b/packages/plugins/components/jest.config.js @@ -0,0 +1,6 @@ +/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +const sharedConfig = require('../../../script/test/jest.base.js'); + +module.exports = { + ...sharedConfig, +}; diff --git a/packages/plugins/components/package.json b/packages/plugins/components/package.json index b40b75280..b7e9692ac 100644 --- a/packages/plugins/components/package.json +++ b/packages/plugins/components/package.json @@ -5,6 +5,7 @@ "main": "./dist/index.js", "module": "./lib/esm/index.js", "types": "./lib/esm/index.d.ts", + "license": "Apache-2.0", "private": false, "publishConfig": { "access": "public", @@ -13,7 +14,8 @@ "scripts": { "build": "yarn build:esm && yarn build:cjs", "build:esm": "tsc --module esnext --outDir lib/esm", - "build:cjs": "tsc" + "build:cjs": "tsc", + "test": "NODE_ENV=test jest" }, "dependencies": { "@material-ui/core": "^4.0.0", diff --git a/packages/plugins/components/src/NavBar/index.tsx b/packages/plugins/components/src/NavBar/index.tsx index 39ee1ff37..1e0b7509a 100644 --- a/packages/plugins/components/src/NavBar/index.tsx +++ b/packages/plugins/components/src/NavBar/index.tsx @@ -21,7 +21,7 @@ export const NavBar = (props: NavBarProps) => { elevation={0} id="navbar" position="fixed" - className={props.className} + className={props.className as string} > {/* {content} */} diff --git a/packages/plugins/components/src/NavBar/navbar.test.tsx b/packages/plugins/components/src/NavBar/navbar.test.tsx index 5b7ad96d7..bc0209e1e 100644 --- a/packages/plugins/components/src/NavBar/navbar.test.tsx +++ b/packages/plugins/components/src/NavBar/navbar.test.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import * as React from 'react'; import { render, screen } from '@testing-library/react'; import { NavBar, add } from './index'; @@ -10,7 +10,7 @@ describe('add function', () => { it('NavBar contains correct text', () => { render(); - const text = screen.getByText("It's me - Navigation Bar"); + const text = screen.getByText('NASTYA IS HERE'); expect(text).toBeInTheDocument(); }); }); diff --git a/packages/zapp/console/jest.config.js b/packages/zapp/console/jest.config.js index f04f9c7ba..52d5b8960 100644 --- a/packages/zapp/console/jest.config.js +++ b/packages/zapp/console/jest.config.js @@ -1,40 +1,28 @@ +/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +const sharedConfig = require('../../../script/test/jest.base.js'); + module.exports = { - preset: 'ts-jest', - testEnvironment: 'jsdom', + ...sharedConfig, testPathIgnorePatterns: ['__stories__', '.storybook', 'node_modules', 'dist', 'build'], setupFilesAfterEnv: ['/src/test/setupTests.ts'], - clearMocks: true, - verbose: false, - moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'node'], modulePaths: ['/src'], roots: ['/src'], transformIgnorePatterns: ['/node_modules/(?!@flyteorg/flyteidl)', 'protobufjs/minimal'], - transform: { - '^.+\\.(j|t)sx?$': 'ts-jest', - }, + moduleNameMapper: { - '@flyteconsole/(.*)': [ - '/../../../packages/plugins/$1/src', - '/../../../packages/zapp/$1/src', - ], + ...sharedConfig.moduleNameMapper, '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '/assetsTransformer.js', }, - coverageDirectory: '../../../.coverage', - collectCoverageFrom: ['**/*.{ts,tsx}', '!**/*/*.stories.{ts,tsx}', '!**/*/*.mocks.{ts,tsx}'], coveragePathIgnorePatterns: [ + ...sharedConfig.coveragePathIgnorePatterns, '__stories__', - '__mocks__', - '/.storybook', - '/node_modules', - '/dist', - '/build', - '/src/tsd', - '/src/server.ts', - '/.eslintrc.js', - '\\.config.js$', + 'src/components/App.tsx', + 'src/tsd', + 'src/client.tsx', + 'src/protobuf.ts', + 'src/server.ts', ], - coverageReporters: ['text', 'json', 'html'], }; diff --git a/packages/zapp/console/package.json b/packages/zapp/console/package.json index fa1706344..6a0b0863a 100644 --- a/packages/zapp/console/package.json +++ b/packages/zapp/console/package.json @@ -18,8 +18,7 @@ "fix": "yarn lint --fix && yarn format", "mockApi": "node ./mockApi", "tdd": "yarn run test --watch --verbose false", - "test": "NODE_ENV=test jest --config=jest.config.js", - "test-coverage": "NODE_ENV=test jest --coverage --config=jest.config.js" + "test": "NODE_ENV=test jest" }, "keywords": [ "react", @@ -74,15 +73,11 @@ "@semantic-release/github": "^7.0.5", "@semantic-release/npm": "^7.0.5", "@semantic-release/release-notes-generator": "^9.0.1", - "@testing-library/jest-dom": "^5.5.0", - "@testing-library/react": "^10.0.3", - "@testing-library/react-hooks": "^7.0.2", "@types/cheerio": "^0.22.2", "@types/d3-shape": "^1.2.6", "@types/debug": "^0.0.30", "@types/dom-helpers": "^3.4.1", "@types/express": "^4.17.2", - "@types/jest": "^26.0.0", "@types/js-yaml": "^3.10.1", "@types/linkify-it": "^2.1.0", "@types/lodash": "^4.14.68", @@ -108,7 +103,6 @@ "axios": "^0.21.2", "axios-mock-adapter": "^1.16.0", "babel-core": "^7.0.0-0", - "babel-jest": "^26.0.0", "babel-loader": "^8.2.3", "camelcase-keys": "^6.1.1", "classnames": "^2.3.1", @@ -133,7 +127,6 @@ "html-webpack-plugin": "^5.5.0", "husky": "^4.2.5", "intersection-observer": "^0.7.0", - "jest": "^26.0.0", "linkify-it": "^2.2.0", "lint-staged": "^7.0.4", "lossless-json": "^1.0.3", @@ -161,7 +154,6 @@ "shallowequal": "^1.1.0", "snakecase-keys": "^3.1.0", "source-map-loader": "^3.0.1", - "ts-jest": "^26.3.0", "ts-loader": "^9.2.6", "ts-node": "^8.0.2", "typescript": "^4.6.2", diff --git a/script/test/jest-setup.ts b/script/test/jest-setup.ts new file mode 100644 index 000000000..7b0828bfa --- /dev/null +++ b/script/test/jest-setup.ts @@ -0,0 +1 @@ +import '@testing-library/jest-dom'; diff --git a/script/test/jest.base.js b/script/test/jest.base.js new file mode 100644 index 000000000..6b607e83a --- /dev/null +++ b/script/test/jest.base.js @@ -0,0 +1,16 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'jsdom', + setupFilesAfterEnv: ['../../../script/test/jest-setup.ts'], + testPathIgnorePatterns: ['dist', 'node_modules', 'lib'], + moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'node'], + transform: { + '^.+\\.(j|t)sx?$': 'ts-jest', + }, + + moduleNameMapper: { + '@flyteconsole/(.*)': ['/packages/plugins/$1/src', '/packages/zapp/$1/src'], + }, + + coveragePathIgnorePatterns: ['mocks', 'src/index'], +}; diff --git a/yarn.lock b/yarn.lock index e04f21af6..fb9323a52 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4091,7 +4091,7 @@ dependencies: "@types/istanbul-lib-report" "*" -"@types/jest@*", "@types/jest@26.x", "@types/jest@^26.0.0": +"@types/jest@*", "@types/jest@26.x": version "26.0.16" resolved "https://registry.yarnpkg.com/@types/jest/-/jest-26.0.16.tgz#b47abd50f6ed0503f589db8e126fc8eb470cf87c" integrity sha512-Gp12+7tmKCgv9JjtltxUXokohCAEZfpJaEW5tn871SGRp8I+bRWBonQO7vW5NHwnAHe5dd50+Q4zyKuN35i09g== @@ -5529,7 +5529,7 @@ babel-core@^7.0.0-0: resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece" integrity sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg== -babel-jest@^26.0.0, babel-jest@^26.6.3: +babel-jest@^26.6.3: version "26.6.3" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-26.6.3.tgz#d87d25cb0037577a0c89f82e5755c5d293c01056" integrity sha512-pl4Q+GAVOHwvjrck6jKjvmGhnO3jHX/xuB9d27f+EJZ/6k+6nMuPjorrYp7s++bKKdANwzElBWnLWaObvTnaZA==