@langri-sha/projen-jest-config 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +34 -0
- package/CHANGELOG.md +18 -0
- package/lib/index.d.ts +28 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +42 -0
- package/lib/index.js.map +1 -0
- package/license +10 -0
- package/package.json +38 -0
- package/readme +54 -0
- package/src/index.ts +59 -0
package/CHANGELOG.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@langri-sha/projen-jest-config",
|
|
3
|
+
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"date": "Sat, 25 May 2024 03:25:02 GMT",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"tag": "@langri-sha/projen-jest-config_v0.1.0",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"author": "filip.dupanovic@gmail.com",
|
|
12
|
+
"package": "@langri-sha/projen-jest-config",
|
|
13
|
+
"commit": "1b0960cb6ed3918c64dbc464cb2baa83f5dc9bdd",
|
|
14
|
+
"comment": "feat(jest-config): Add package for configuring Jest"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"author": "filip.dupanovic@gmail.com",
|
|
18
|
+
"package": "@langri-sha/projen-jest-config",
|
|
19
|
+
"commit": "1b0960cb6ed3918c64dbc464cb2baa83f5dc9bdd",
|
|
20
|
+
"comment": "feat(project): Add projenrc file to subprojects"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"patch": [
|
|
24
|
+
{
|
|
25
|
+
"author": "filip.dupanovic@gmail.com",
|
|
26
|
+
"package": "@langri-sha/projen-jest-config",
|
|
27
|
+
"commit": "1b0960cb6ed3918c64dbc464cb2baa83f5dc9bdd",
|
|
28
|
+
"comment": "fix(jest): Update documentation URL"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Change Log - @langri-sha/projen-jest-config
|
|
2
|
+
|
|
3
|
+
This log was last generated on Sat, 25 May 2024 03:25:02 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
<!-- Start content -->
|
|
6
|
+
|
|
7
|
+
## 0.1.0
|
|
8
|
+
|
|
9
|
+
Sat, 25 May 2024 03:25:02 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- feat(jest-config): Add package for configuring Jest (filip.dupanovic@gmail.com)
|
|
14
|
+
- feat(project): Add projenrc file to subprojects (filip.dupanovic@gmail.com)
|
|
15
|
+
|
|
16
|
+
### Patches
|
|
17
|
+
|
|
18
|
+
- fix(jest): Update documentation URL (filip.dupanovic@gmail.com)
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FileBase, IResolver, Project } from 'projen';
|
|
2
|
+
import { Config } from 'jest';
|
|
3
|
+
/**
|
|
4
|
+
* Options for configuring Jest.
|
|
5
|
+
*/
|
|
6
|
+
export interface JestConfigOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Name of the Jest config module.
|
|
9
|
+
*
|
|
10
|
+
* @default 'jest.config.ts'
|
|
11
|
+
*/
|
|
12
|
+
filename?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Name of a Jest configuration package to extend from.
|
|
15
|
+
*/
|
|
16
|
+
extends?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Jest configuration object.
|
|
19
|
+
*/
|
|
20
|
+
config?: Config;
|
|
21
|
+
}
|
|
22
|
+
export declare class JestConfig extends FileBase {
|
|
23
|
+
#private;
|
|
24
|
+
config: Config;
|
|
25
|
+
constructor(project: Project, options?: JestConfigOptions);
|
|
26
|
+
protected synthesizeContent(_: IResolver): string | undefined;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAG7B;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,qBAAa,UAAW,SAAQ,QAAQ;;IAEtC,MAAM,EAAE,MAAM,CAAA;gBAEF,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,iBAAsB;cAY1C,iBAAiB,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;CAgBvE"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _JestConfig_extends;
|
|
13
|
+
import { FileBase } from 'projen';
|
|
14
|
+
import serialize from 'serialize-javascript';
|
|
15
|
+
export class JestConfig extends FileBase {
|
|
16
|
+
constructor(project, options = {}) {
|
|
17
|
+
const filename = options.filename ?? 'jest.config.ts';
|
|
18
|
+
super(project, filename, {
|
|
19
|
+
readonly: true,
|
|
20
|
+
marker: true,
|
|
21
|
+
});
|
|
22
|
+
_JestConfig_extends.set(this, void 0);
|
|
23
|
+
__classPrivateFieldSet(this, _JestConfig_extends, options.extends, "f");
|
|
24
|
+
this.config = options.config ?? {};
|
|
25
|
+
}
|
|
26
|
+
synthesizeContent(_) {
|
|
27
|
+
const config = {
|
|
28
|
+
...this.config,
|
|
29
|
+
};
|
|
30
|
+
const serialized = serialize(config);
|
|
31
|
+
return `import type { Config } from 'jest'${__classPrivateFieldGet(this, _JestConfig_extends, "f") ? `\nimport defaults from '${__classPrivateFieldGet(this, _JestConfig_extends, "f")}'` : ''}
|
|
32
|
+
|
|
33
|
+
const config: Config = {
|
|
34
|
+
${__classPrivateFieldGet(this, _JestConfig_extends, "f") ? `...defaults,` : ''}
|
|
35
|
+
${serialized.slice(1)}
|
|
36
|
+
|
|
37
|
+
export default config
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
_JestConfig_extends = new WeakMap();
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,QAAQ,CAAA;AAErD,OAAO,SAAS,MAAM,sBAAsB,CAAA;AAwB5C,MAAM,OAAO,UAAW,SAAQ,QAAQ;IAItC,YAAY,OAAgB,EAAE,UAA6B,EAAE;QAC3D,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,gBAAgB,CAAA;QAErD,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE;YACvB,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,IAAI;SACb,CAAC,CAAA;QATJ,sCAAiB;QAWf,uBAAA,IAAI,uBAAY,OAAO,CAAC,OAAO,MAAA,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAA;IACpC,CAAC;IAEkB,iBAAiB,CAAC,CAAY;QAC/C,MAAM,MAAM,GAAW;YACrB,GAAG,IAAI,CAAC,MAAM;SACf,CAAA;QAED,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;QAEpC,OAAO,qCAAqC,uBAAA,IAAI,2BAAS,CAAC,CAAC,CAAC,2BAA2B,uBAAA,IAAI,2BAAS,GAAG,CAAC,CAAC,CAAC,EAAE;;;QAGxG,uBAAA,IAAI,2BAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE;QACnC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;;;KAGtB,CAAA;IACH,CAAC;CACF"}
|
package/license
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2024 Filip Dupanović <filip.dupanovic@gmail.com> (https://langri-sha.com)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@langri-sha/projen-jest-config",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Filip Dupanović",
|
|
7
|
+
"email": "filip.dupanovic@gmail.com",
|
|
8
|
+
"url": "https://langri-sha.com",
|
|
9
|
+
"organization": false
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "lib/index.js",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"prepublishOnly": "rm -rf lib; tsc --project tsconfig.build.json"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"serialize-javascript": "6.0.2"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@langri-sha/jest-test": "0.7.1",
|
|
21
|
+
"@langri-sha/tsconfig": "0.9.0",
|
|
22
|
+
"@types/serialize-javascript": "5.0.4",
|
|
23
|
+
"jest": "^28.00 || ^29.00",
|
|
24
|
+
"projen": "0.81.15"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"jest": "^28.00 || ^29.00",
|
|
28
|
+
"projen": "^0.81.15"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">= 20.12.0"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"//": "~~ Generated by projen. To modify, edit .projenrc.mts and run \"npx projen\".",
|
|
37
|
+
"types": "lib/index.d.ts"
|
|
38
|
+
}
|
package/readme
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @langri-sha/projen-jest-config
|
|
2
|
+
|
|
3
|
+
A [projen] component for authoring [Jest] configurations. This component is
|
|
4
|
+
suitable for monorepos and offers support for extending from an existing Jest
|
|
5
|
+
configuration.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
Install required dependencies:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install -D jest @langri-sha/projen-jest-config
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Configure Jest for your project:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// .projenrc.ts
|
|
19
|
+
import { Project } from 'projen'
|
|
20
|
+
import { JestConfig } from '@langri-sha/projen-jest-config'
|
|
21
|
+
|
|
22
|
+
const project = new Project({
|
|
23
|
+
name: 'my-project',
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
new JestConfig(project, {
|
|
27
|
+
// Configure the desired Jest configuration module. Optional.
|
|
28
|
+
filename: 'jest.config.ts',
|
|
29
|
+
// Choose a desired Jest configuration module. Optional.
|
|
30
|
+
extends: '@langri-sha/jest-config',
|
|
31
|
+
// Inline your preferred configuration overrides.
|
|
32
|
+
config: {
|
|
33
|
+
testEnvironment: 'node',
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
This should produce the following output:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
// jest.config.ts
|
|
42
|
+
import type { Config } from 'jest'
|
|
43
|
+
import defaults from '@langri-sha/jest-config'
|
|
44
|
+
|
|
45
|
+
const config: Config = {
|
|
46
|
+
...defaults,
|
|
47
|
+
testEnvironment: 'node',
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default config
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
[projen]: https://projen.io/
|
|
54
|
+
[jest]: https://jestjs.io/docs/
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { FileBase, IResolver, Project } from 'projen'
|
|
2
|
+
import { Config } from 'jest'
|
|
3
|
+
import serialize from 'serialize-javascript'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for configuring Jest.
|
|
7
|
+
*/
|
|
8
|
+
export interface JestConfigOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Name of the Jest config module.
|
|
11
|
+
*
|
|
12
|
+
* @default 'jest.config.ts'
|
|
13
|
+
*/
|
|
14
|
+
filename?: string
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Name of a Jest configuration package to extend from.
|
|
18
|
+
*/
|
|
19
|
+
extends?: string
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Jest configuration object.
|
|
23
|
+
*/
|
|
24
|
+
config?: Config
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class JestConfig extends FileBase {
|
|
28
|
+
#extends?: string
|
|
29
|
+
config: Config
|
|
30
|
+
|
|
31
|
+
constructor(project: Project, options: JestConfigOptions = {}) {
|
|
32
|
+
const filename = options.filename ?? 'jest.config.ts'
|
|
33
|
+
|
|
34
|
+
super(project, filename, {
|
|
35
|
+
readonly: true,
|
|
36
|
+
marker: true,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
this.#extends = options.extends
|
|
40
|
+
this.config = options.config ?? {}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
protected override synthesizeContent(_: IResolver): string | undefined {
|
|
44
|
+
const config: Config = {
|
|
45
|
+
...this.config,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const serialized = serialize(config)
|
|
49
|
+
|
|
50
|
+
return `import type { Config } from 'jest'${this.#extends ? `\nimport defaults from '${this.#extends}'` : ''}
|
|
51
|
+
|
|
52
|
+
const config: Config = {
|
|
53
|
+
${this.#extends ? `...defaults,` : ''}
|
|
54
|
+
${serialized.slice(1)}
|
|
55
|
+
|
|
56
|
+
export default config
|
|
57
|
+
`
|
|
58
|
+
}
|
|
59
|
+
}
|