File size: 993 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# @automattic/calypso-jest

This package provides a Jest preset used to run tests in Calypso. In your `jest.config.js` set the following:

```js
module.exports = {
	preset: '@automattic/calypso-jest',
};
```

Major features:

- Find tests under `<rootDir>` inside `test` folder. Valid extensions are `.ts`, `.js`, `.tsx`, `.jsx`
- Can use `calypso:src` from `package.json` to resolve a package
- Can use conditional exports

## Assets transformer

Jest would fail when trying to import asset files that it cannot parse,
i.e. they're not plain JavaScript:

```jsx
const MyFlag = ( { countryCode } ) => (
	<img alt="" src={ require( `flags/${ countryCode }.svg` ).default } />
);
```

This packages includes a transfomer that be used to transform all those imports to a module that returns
the asset file's basename as a string:

```js
const config = {
	transform: {
		'\\.(gif|jpg|jpeg|png|svg|scss|sass|css)$': require.resolve(
			'@automattic/calypso-jest/asset-transform.js'
		),
	},
};
```