From 122338af4c4358d9c8598cf459ed42e7bf9186b1 Mon Sep 17 00:00:00 2001 From: DAK <40970507+dakahn@users.noreply.github.com> Date: Fri, 20 Nov 2020 11:54:51 -0600 Subject: [PATCH] feat(project): add jest-config-carbon (#7315) * feat(project): add jest-config-carbon * chore(project): update yarn.lock * chore(format): run prettier Co-authored-by: Josh Black Co-authored-by: TJ Egan Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .stylelintignore | 1 + config/jest-config-carbon/.npmignore | 4 ++ config/jest-config-carbon/README.md | 29 +++++++++ config/jest-config-carbon/index.js | 49 +++++++++++++++ config/jest-config-carbon/jest-preset.js | 12 ++++ .../matchers/toHaveNoACViolations.js | 0 .../matchers/toHaveNoAxeViolations.js | 0 .../matchers/toHaveNoDAPViolations.js | 0 config/jest-config-carbon/package.json | 40 +++++++++++++ .../jest-config-carbon/setup}/setup.js | 0 .../setup}/setupAfterEnv.js | 6 +- .../transform}/cssTransform.js | 0 .../transform}/fileTransform.js | 0 .../transform}/jsTransform.js | 0 package.json | 59 +------------------ yarn.lock | 8 +-- 16 files changed, 144 insertions(+), 64 deletions(-) create mode 100644 config/jest-config-carbon/.npmignore create mode 100644 config/jest-config-carbon/README.md create mode 100644 config/jest-config-carbon/index.js create mode 100644 config/jest-config-carbon/jest-preset.js rename {tasks/jest => config/jest-config-carbon}/matchers/toHaveNoACViolations.js (100%) rename {tasks/jest => config/jest-config-carbon}/matchers/toHaveNoAxeViolations.js (100%) rename {tasks/jest => config/jest-config-carbon}/matchers/toHaveNoDAPViolations.js (100%) create mode 100644 config/jest-config-carbon/package.json rename {tasks/jest => config/jest-config-carbon/setup}/setup.js (100%) rename {tasks/jest => config/jest-config-carbon/setup}/setupAfterEnv.js (92%) rename {tasks/jest => config/jest-config-carbon/transform}/cssTransform.js (100%) rename {tasks/jest => config/jest-config-carbon/transform}/fileTransform.js (100%) rename {tasks/jest => config/jest-config-carbon/transform}/jsTransform.js (100%) diff --git a/.stylelintignore b/.stylelintignore index 7033cfcd95f2..78cae7c2c4df 100644 --- a/.stylelintignore +++ b/.stylelintignore @@ -3,6 +3,7 @@ **/examples/** **/vendor/** **/_inlined/** +**/coverage/** # Generated SCSS directories and files **/packages/colors/**/*.scss diff --git a/config/jest-config-carbon/.npmignore b/config/jest-config-carbon/.npmignore new file mode 100644 index 000000000000..81ba1598b971 --- /dev/null +++ b/config/jest-config-carbon/.npmignore @@ -0,0 +1,4 @@ +**/__mocks__/** +**/__tests__/** +**/examples/** +**/tasks/** \ No newline at end of file diff --git a/config/jest-config-carbon/README.md b/config/jest-config-carbon/README.md new file mode 100644 index 000000000000..1fecf88ab0ce --- /dev/null +++ b/config/jest-config-carbon/README.md @@ -0,0 +1,29 @@ +# jest-config-carbon + +> Jest configuration and preset for Carbon + +## Getting started + +To install `jest-config-carbon` in your project, you will need to run the +following command using [npm](https://www.npmjs.com/): + +```bash +npm install -S jest-config-carbon +``` + +If you prefer [Yarn](https://yarnpkg.com/en/), use the following command +instead: + +```bash +yarn add jest-config-carbon +``` + +## 🙌 Contributing + +We're always looking for contributors to help us fix bugs, build new features, +or help us improve the project documentation. If you're interested, definitely +check out our [Contributing Guide](/.github/CONTRIBUTING.md)! 👀 + +## 📝 License + +Licensed under the [Apache 2.0 License](/LICENSE). diff --git a/config/jest-config-carbon/index.js b/config/jest-config-carbon/index.js new file mode 100644 index 000000000000..ccfaecebdd79 --- /dev/null +++ b/config/jest-config-carbon/index.js @@ -0,0 +1,49 @@ +/** + * Copyright IBM Corp. 2018, 2018 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +'use strict'; + +module.exports = { + moduleFileExtensions: ['js', 'json', 'node'], + reporters: ['default'], + setupFiles: [require.resolve('./setup/setup.js')], + setupFilesAfterEnv: [require.resolve('./setup/setupAfterEnv.js')], + snapshotSerializers: ['enzyme-to-json/serializer'], + testMatch: [ + '/**/__tests__/**/*.js?(x)', + '/**/*.(spec|test).js?(x)', + '/**/*-(spec|test).js?(x)', + ], + transform: { + '^.+\\.(js|jsx)$': require.resolve('./transform/jsTransform.js'), + '^.+\\.css$': require.resolve('./transform/cssTransform.js'), + '^(?!.*\\.(js|jsx|css|json)$)': require.resolve( + './transform/fileTransform.js' + ), + }, + testRunner: 'jest-circus/runner', + testPathIgnorePatterns: [ + '/cjs/', + '/dist/', + '/es/', + '/lib/', + '/build/', + 'e2e', + 'examples', + '/umd/', + ], + transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'], + watchPathIgnorePatterns: [ + '/cjs/', + '/dist/', + '/es/', + '/examples/', + '/lib/', + '/storybook/', + '/results/', + ], +}; diff --git a/config/jest-config-carbon/jest-preset.js b/config/jest-config-carbon/jest-preset.js new file mode 100644 index 000000000000..85193339c374 --- /dev/null +++ b/config/jest-config-carbon/jest-preset.js @@ -0,0 +1,12 @@ +/** + * Copyright IBM Corp. 2018, 2018 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +'use strict'; + +const config = require('./'); + +module.exports = config; diff --git a/tasks/jest/matchers/toHaveNoACViolations.js b/config/jest-config-carbon/matchers/toHaveNoACViolations.js similarity index 100% rename from tasks/jest/matchers/toHaveNoACViolations.js rename to config/jest-config-carbon/matchers/toHaveNoACViolations.js diff --git a/tasks/jest/matchers/toHaveNoAxeViolations.js b/config/jest-config-carbon/matchers/toHaveNoAxeViolations.js similarity index 100% rename from tasks/jest/matchers/toHaveNoAxeViolations.js rename to config/jest-config-carbon/matchers/toHaveNoAxeViolations.js diff --git a/tasks/jest/matchers/toHaveNoDAPViolations.js b/config/jest-config-carbon/matchers/toHaveNoDAPViolations.js similarity index 100% rename from tasks/jest/matchers/toHaveNoDAPViolations.js rename to config/jest-config-carbon/matchers/toHaveNoDAPViolations.js diff --git a/config/jest-config-carbon/package.json b/config/jest-config-carbon/package.json new file mode 100644 index 000000000000..fe61cf17355c --- /dev/null +++ b/config/jest-config-carbon/package.json @@ -0,0 +1,40 @@ +{ + "name": "jest-config-carbon", + "private": true, + "description": "Jest configuration and preset for Carbon", + "dependencies": { + "@babel/core": "^7.10.0", + "@babel/plugin-proposal-class-properties": "^7.7.4", + "@babel/plugin-proposal-export-default-from": "^7.7.4", + "@babel/plugin-proposal-export-namespace-from": "^7.7.4", + "@babel/plugin-transform-runtime": "^7.10.0", + "@babel/preset-env": "^7.10.0", + "@babel/preset-react": "^7.10.0", + "@babel/runtime": "^7.10.0", + "@ibma/aat": "https://able.ibm.com/tools/dist/ibma-aat-2.0.6.tgz", + "accessibility-checker": "^3.1.1", + "axe-core": "^3.3.2", + "babel-jest": "^26.0.1", + "chalk": "^4.1.0", + "enzyme": "^3.10.0", + "enzyme-adapter-react-16": "^1.14.0", + "enzyme-to-json": "^3.3.5", + "jest-circus": "^26.0.1" + }, + "version": "0.0.0", + "license": "Apache-2.0", + "main": "index.js", + "repository": { + "type": "git", + "url": "https://github.com/carbon-design-system/carbon.git", + "directory": "config/jest-config-carbon" + }, + "bugs": "https://github.com/carbon-design-system/carbon/issues", + "keywords": [ + "ibm", + "carbon", + "carbon-design-system", + "components", + "react" + ] +} diff --git a/tasks/jest/setup.js b/config/jest-config-carbon/setup/setup.js similarity index 100% rename from tasks/jest/setup.js rename to config/jest-config-carbon/setup/setup.js diff --git a/tasks/jest/setupAfterEnv.js b/config/jest-config-carbon/setup/setupAfterEnv.js similarity index 92% rename from tasks/jest/setupAfterEnv.js rename to config/jest-config-carbon/setup/setupAfterEnv.js index a9c1cd9b7202..18ac7c927e2a 100644 --- a/tasks/jest/setupAfterEnv.js +++ b/config/jest-config-carbon/setup/setupAfterEnv.js @@ -7,9 +7,9 @@ const chalk = require('chalk'); const util = require('util'); -const toHaveNoAxeViolations = require('./matchers/toHaveNoAxeViolations'); -const toHaveNoDAPViolations = require('./matchers/toHaveNoDAPViolations'); -const toHaveNoACViolations = require('./matchers/toHaveNoACViolations'); +const toHaveNoAxeViolations = require('../matchers/toHaveNoAxeViolations'); +const toHaveNoDAPViolations = require('../matchers/toHaveNoDAPViolations'); +const toHaveNoACViolations = require('../matchers/toHaveNoACViolations'); // We can extend `expect` using custom matchers as defined by: // https://jest-bot.github.io/jest/docs/expect.html#expectextendmatchers diff --git a/tasks/jest/cssTransform.js b/config/jest-config-carbon/transform/cssTransform.js similarity index 100% rename from tasks/jest/cssTransform.js rename to config/jest-config-carbon/transform/cssTransform.js diff --git a/tasks/jest/fileTransform.js b/config/jest-config-carbon/transform/fileTransform.js similarity index 100% rename from tasks/jest/fileTransform.js rename to config/jest-config-carbon/transform/fileTransform.js diff --git a/tasks/jest/jsTransform.js b/config/jest-config-carbon/transform/jsTransform.js similarity index 100% rename from tasks/jest/jsTransform.js rename to config/jest-config-carbon/transform/jsTransform.js diff --git a/package.json b/package.json index 04b199c1267e..09c17075a22d 100644 --- a/package.json +++ b/package.json @@ -46,27 +46,19 @@ "@babel/runtime": "^7.10.0", "@commitlint/cli": "^8.3.5", "@commitlint/config-conventional": "^8.3.4", - "@ibma/aat": "https://able.ibm.com/tools/dist/ibma-aat-2.0.6.tgz", "@testing-library/dom": "^7.26.6", "@testing-library/jest-dom": "^5.11.5", "@testing-library/react": "^11.1.1", "@testing-library/user-event": "^12.2.0", - "accessibility-checker": "^3.1.1", "all-contributors-cli": "^6.19.0", - "axe-core": "^3.3.2", - "babel-jest": "^26.0.1", "cross-env": "^5.2.0", "cross-spawn": "^6.0.5", "doctoc": "^1.4.0", - "enzyme": "^3.10.0", - "enzyme-adapter-react-16": "^1.14.0", - "enzyme-to-json": "^3.3.5", "eslint": "^6.8.0", "fs-extra": "^8.1.0", "glob": "^7.1.4", "husky": "^4.0.10", "jest": "^26.0.1", - "jest-circus": "^26.0.1", "jest-junit": "^10.0.0", "lerna": "^3.20.2", "lint-staged": "^9.5.0", @@ -148,63 +140,16 @@ ] }, "jest": { + "preset": "jest-config-carbon", "collectCoverageFrom": [ "packages/**/src/**/*.js", "!packages/{bundler,cli,components,sketch}/**", "!packages/**/{examples,stories}/**", "!**/*-story.js" ], - "moduleFileExtensions": [ - "js", - "json", - "node" - ], "reporters": [ "default", "jest-junit" - ], - "setupFiles": [ - "./tasks/jest/setup.js" - ], - "setupFilesAfterEnv": [ - "./tasks/jest/setupAfterEnv.js" - ], - "snapshotSerializers": [ - "enzyme-to-json/serializer" - ], - "testMatch": [ - "/**/__tests__/**/*.js?(x)", - "/**/*.(spec|test).js?(x)", - "/**/*-(spec|test).js?(x)" - ], - "transform": { - "^.+\\.(js|jsx)$": "./tasks/jest/jsTransform.js", - "^.+\\.css$": "./tasks/jest/cssTransform.js", - "^(?!.*\\.(js|jsx|css|json)$)": "./tasks/jest/fileTransform.js" - }, - "testRunner": "jest-circus/runner", - "testPathIgnorePatterns": [ - "/cjs/", - "/dist/", - "/es/", - "/lib/", - "/build/", - "e2e", - "examples", - "/umd/" - ], - "transformIgnorePatterns": [ - "[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$" - ], - "watchPathIgnorePatterns": [ - "/cjs/", - "/dist/", - "/es/", - "/examples/", - "/lib/", - "/storybook/", - "/results/" ] - }, - "dependencies": {} + } } diff --git a/yarn.lock b/yarn.lock index 38ac460c3f6e..4a78c2cbb939 100644 --- a/yarn.lock +++ b/yarn.lock @@ -20740,7 +20740,7 @@ react-docgen@^5.0.0: react-dom@^16.6.0, react-dom@^16.8.3, react-dom@^16.8.6, react-dom@^16.9.0, react-dom@~16.9.0: version "16.9.0" - resolved "https://registry.npmjs.org/react-dom/-/react-dom-16.9.0.tgz#5e65527a5e26f22ae3701131bcccaee9fb0d3962" + resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.9.0.tgz#5e65527a5e26f22ae3701131bcccaee9fb0d3962" integrity sha512-YFT2rxO9hM70ewk9jq0y6sQk8cL02xm4+IzYBz75CQGlClQQ1Bxq0nhHF6OtSbit+AIahujJgb/CPRibFkMNJQ== dependencies: loose-envify "^1.1.0" @@ -20828,7 +20828,7 @@ react-inspector@^4.0.0: react-is@^16.12.0, react-is@^16.13.1, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.2, react-is@^16.8.4, react-is@^16.8.6, react-is@^16.9.0, react-is@^17.0.1, react-is@~16.9.0: version "16.9.0" - resolved "https://registry.npmjs.org/react-is/-/react-is-16.9.0.tgz#21ca9561399aad0ff1a7701c01683e8ca981edcb" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.9.0.tgz#21ca9561399aad0ff1a7701c01683e8ca981edcb" integrity sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw== react-lifecycles-compat@^3.0.4: @@ -20894,7 +20894,7 @@ react-syntax-highlighter@^11.0.2: react-test-renderer@^16.0.0-0, react-test-renderer@^16.8.6, react-test-renderer@~16.9.0: version "16.9.0" - resolved "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-16.9.0.tgz#7ed657a374af47af88f66f33a3ef99c9610c8ae9" + resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.9.0.tgz#7ed657a374af47af88f66f33a3ef99c9610c8ae9" integrity sha512-R62stB73qZyhrJo7wmCW9jgl/07ai+YzvouvCXIJLBkRlRqLx4j9RqcLEAfNfU3OxTGucqR2Whmn3/Aad6L3hQ== dependencies: object-assign "^4.1.1" @@ -20922,7 +20922,7 @@ react-transition-group@^2.2.1: react@^16.6.0, react@^16.8.3, react@^16.8.6, react@^16.9.0, react@~16.9.0: version "16.9.0" - resolved "https://registry.npmjs.org/react/-/react-16.9.0.tgz#40ba2f9af13bc1a38d75dbf2f4359a5185c4f7aa" + resolved "https://registry.yarnpkg.com/react/-/react-16.9.0.tgz#40ba2f9af13bc1a38d75dbf2f4359a5185c4f7aa" integrity sha512-+7LQnFBwkiw+BobzOF6N//BdoNw0ouwmSJTEm9cglOOmsg/TMiFHZLe2sEoN5M7LgJTj9oHH0gxklfnQe66S1w== dependencies: loose-envify "^1.1.0"