Skip to content

Commit 7bc92e0

Browse files
committed
test: initial jest config
1 parent e17fbe0 commit 7bc92e0

File tree

10 files changed

+17342
-10266
lines changed

10 files changed

+17342
-10266
lines changed

TESTING_README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@
22

33
As this library is the base of all monday's ui and future open source library, its components should be very well tested. In order to do so we've chosen the following test stack.
44

5+
We are using two approaches when regarding testing the first is the standard jest stack:
6+
1. Jest as of our test runner and framework
7+
2. [React testing library](https://testing-library.com/docs/react-testing-library/intro) as our components testing library
8+
9+
The second approach is for special use cases which require a browser (positing, observer callbacks ...)
510
1. Karna as our test runner
611
2. Mocha as our framework library
712
3. Sinon as our mocks/stubs library
8-
4. [React testing library](https://testing-library.com/docs/react-testing-library/intro) as our components testing frame work
13+
4. [React testing library](https://testing-library.com/docs/react-testing-library/intro) as our components testing library
914

1015
## React testing library
1116
This library forces us to test according to user behaviour and not implementation details (state keys for example) for example the library allows you to target elements according to text, aria labels, placeholders text and more. This approach ensure us that we test the component in the right way and allows us easier refactoring when needed.
1217

1318
#### Test File
14-
The file should end with `-test.js` and be in the same folder as the component.
19+
#### Jest
20+
Use our plop which automatically generates the proper folder structure, each file should end with .test.js
21+
22+
#### Karma
23+
The file should end with `-test.js` and should be located in a `__tests__` folder.
1524

1625
### React testing 101
1726
#### Mounting components

__mocks__/styleMock.js

Whitespace-only changes.

jest.config.js

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property, visit:
3+
* https://jestjs.io/docs/en/configuration.html
4+
*/
5+
6+
module.exports = {
7+
// All imported modules in your tests should be mocked automatically
8+
// automock: false,
9+
10+
// Stop running tests after `n` failures
11+
// bail: 0,
12+
13+
// The directory where Jest should store its cached dependency information
14+
// cacheDirectory: "/private/var/folders/cc/y9txhz0x3k32xxwxbcc92b7m0000gn/T/jest_dx",
15+
16+
// Automatically clear mock calls and instances between every test
17+
clearMocks: true,
18+
19+
// Indicates whether the coverage information should be collected while executing the test
20+
// collectCoverage: false,
21+
22+
// An array of glob patterns indicating a set of files for which coverage information should be collected
23+
// collectCoverageFrom: undefined,
24+
25+
// The directory where Jest should output its coverage files
26+
coverageDirectory: "coverage",
27+
28+
// An array of regexp pattern strings used to skip coverage collection
29+
// coveragePathIgnorePatterns: [
30+
// "/node_modules/"
31+
// ],
32+
33+
// Indicates which provider should be used to instrument code for coverage
34+
// coverageProvider: "babel",
35+
36+
// A list of reporter names that Jest uses when writing coverage reports
37+
// coverageReporters: [
38+
// "json",
39+
// "text",
40+
// "lcov",
41+
// "clover"
42+
// ],
43+
44+
// An object that configures minimum threshold enforcement for coverage results
45+
// coverageThreshold: undefined,
46+
47+
// A path to a custom dependency extractor
48+
// dependencyExtractor: undefined,
49+
50+
// Make calling deprecated APIs throw helpful error messages
51+
// errorOnDeprecated: false,
52+
53+
// Force coverage collection from ignored files using an array of glob patterns
54+
// forceCoverageMatch: [],
55+
56+
// A path to a module which exports an async function that is triggered once before all test suites
57+
// globalSetup: undefined,
58+
59+
// A path to a module which exports an async function that is triggered once after all test suites
60+
// globalTeardown: undefined,
61+
62+
// A set of global variables that need to be available in all test environments
63+
// globals: {},
64+
65+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
66+
// maxWorkers: "50%",
67+
68+
// An array of directory names to be searched recursively up from the requiring module's location
69+
// moduleDirectories: [
70+
// "node_modules"
71+
// ],
72+
73+
// An array of file extensions your modules use
74+
// moduleFileExtensions: [
75+
// "js",
76+
// "json",
77+
// "jsx",
78+
// "ts",
79+
// "tsx",
80+
// "node"
81+
// ],
82+
83+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
84+
moduleNameMapper: {
85+
"\\.(css|less|sass|scss)$": "<rootDir>/__mocks__/styleMock.js",
86+
87+
},
88+
89+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
90+
// modulePathIgnorePatterns: [],
91+
92+
// Activates notifications for test results
93+
// notify: false,
94+
95+
// An enum that specifies notification mode. Requires { notify: true }
96+
// notifyMode: "failure-change",
97+
98+
// A preset that is used as a base for Jest's configuration
99+
// preset: undefined,
100+
101+
// Run tests from one or more projects
102+
// projects: undefined,
103+
104+
// Use this configuration option to add custom reporters to Jest
105+
// reporters: undefined,
106+
107+
// Automatically reset mock state between every test
108+
// resetMocks: false,
109+
110+
// Reset the module registry before running each individual test
111+
// resetModules: false,
112+
113+
// A path to a custom resolver
114+
// resolver: undefined,
115+
116+
// Automatically restore mock state between every test
117+
// restoreMocks: false,
118+
119+
// The root directory that Jest should scan for tests and modules within
120+
// rootDir: undefined,
121+
122+
// A list of paths to directories that Jest should use to search for files in
123+
// roots: [
124+
// "<rootDir>"
125+
// ],
126+
127+
// Allows you to use a custom runner instead of Jest's default test runner
128+
// runner: "jest-runner",
129+
130+
// The paths to modules that run some code to configure or set up the testing environment before each test
131+
// setupFiles: [],
132+
133+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
134+
// setupFilesAfterEnv: [],
135+
136+
// The number of seconds after which a test is considered as slow and reported as such in the results.
137+
// slowTestThreshold: 5,
138+
139+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
140+
// snapshotSerializers: [],
141+
142+
// The test environment that will be used for testing
143+
// testEnvironment: "jest-environment-jsdom",
144+
145+
// Options that will be passed to the testEnvironment
146+
// testEnvironmentOptions: {},
147+
148+
// Adds a location field to test results
149+
// testLocationInResults: false,
150+
151+
// The glob patterns Jest uses to detect test files
152+
testMatch: ["**/__tests__/**/*.test.[jt]s?(x)"]
153+
154+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
155+
// testPathIgnorePatterns: [
156+
// "/node_modules/"
157+
// ],
158+
159+
// The regexp pattern or array of patterns that Jest uses to detect test files
160+
// testRegex: [],
161+
162+
// This option allows the use of a custom results processor
163+
// testResultsProcessor: undefined,
164+
165+
// This option allows use of a custom test runner
166+
// testRunner: "jasmine2",
167+
168+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
169+
// testURL: "http://localhost",
170+
171+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
172+
// timers: "real",
173+
174+
// A map from regular expressions to paths to transformers
175+
// transform: undefined,
176+
177+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
178+
// transformIgnorePatterns: [
179+
// "/node_modules/",
180+
// "\\.pnp\\.[^\\/]+$"
181+
// ],
182+
183+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
184+
// unmockedModulePathPatterns: undefined,
185+
186+
// Indicates whether each individual test should be reported during the run
187+
// verbose: undefined,
188+
189+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
190+
// watchPathIgnorePatterns: [],
191+
192+
// Whether to use watchman for file crawling
193+
// watchman: true,
194+
};

0 commit comments

Comments
 (0)