@lipemat/js-boilerplate 10.4.0-beta.3 → 10.4.0-beta.4
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/README.md +2 -2
- package/config/jest.config.ts +3 -3
- package/config/tsconfig.json +3 -1
- package/helpers/config.ts +9 -5
- package/helpers/{modules.js → modules.ts} +5 -9
- package/helpers/package-config.ts +2 -3
- package/package.json +1 -2
- package/scripts/test.ts +10 -7
- package/tsconfig.json +5 -6
- package/config/jest.config.js +0 -58
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ This is useful when you have often reused overrides to support a particular libr
|
|
|
88
88
|
|
|
89
89
|
### Testing
|
|
90
90
|
To use the built in testing, copy the following items from `templates` into your project root:
|
|
91
|
-
1. `jest.config.
|
|
91
|
+
1. `jest.config.ts`
|
|
92
92
|
2. `tests`
|
|
93
93
|
|
|
94
94
|
Now you may write `jest` tests as desired and run them via `yarn run test`
|
|
@@ -96,7 +96,7 @@ Now you may write `jest` tests as desired and run them via `yarn run test`
|
|
|
96
96
|
|
|
97
97
|
**Alternatively you may create a [run configuration](https://www.jetbrains.com/help/phpstorm/running-unit-tests-on-jest.html#createRunConfigJest) in PHPStorm for an interactive testing experience.**
|
|
98
98
|
1. __Jest package__: `<project root>/node_modules/jest-cli`
|
|
99
|
-
2. __Working directory__: root of your app which contains the `jest.config.
|
|
99
|
+
2. __Working directory__: root of your app which contains the `jest.config.ts`.
|
|
100
100
|
3. "All tests" to run an entire directory of tests.
|
|
101
101
|
4. "Suite" to run a particular file of tests.
|
|
102
102
|
|
package/config/jest.config.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type {Config} from 'jest';
|
|
|
2
2
|
import {resolve} from 'path';
|
|
3
3
|
const {getPackageConfig} = require( '../helpers/package-config' );
|
|
4
4
|
const {existsSync} = require( 'fs' );
|
|
5
|
-
|
|
5
|
+
import {getConfig} from '../helpers/config';
|
|
6
6
|
|
|
7
7
|
const packageConfig = getPackageConfig();
|
|
8
8
|
const babelConfig = getConfig( 'babel.config' );
|
|
@@ -43,9 +43,9 @@ let jestConfig: Config = {
|
|
|
43
43
|
* @todo Remove in version 11.
|
|
44
44
|
*/
|
|
45
45
|
try {
|
|
46
|
-
const localConfig = require( resolve( packageConfig.workingDirectory + '/config', 'jest.config.
|
|
46
|
+
const localConfig = require( resolve( packageConfig.workingDirectory + '/config', 'jest.config.ts' ) );
|
|
47
47
|
jestConfig = {...jestConfig, ...localConfig};
|
|
48
48
|
} catch ( e ) {
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
export default jestConfig;
|
package/config/tsconfig.json
CHANGED
|
@@ -5,18 +5,20 @@
|
|
|
5
5
|
"display": "JS Boilerplate",
|
|
6
6
|
"compilerOptions": {
|
|
7
7
|
"allowSyntheticDefaultImports": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
8
9
|
"forceConsistentCasingInFileNames": true,
|
|
9
10
|
"jsx": "preserve",
|
|
10
11
|
"lib": [
|
|
11
12
|
"dom",
|
|
12
13
|
"es2018"
|
|
13
14
|
],
|
|
14
|
-
"module": "
|
|
15
|
+
"module": "Node16",
|
|
15
16
|
"moduleResolution": "Node",
|
|
16
17
|
"noFallthroughCasesInSwitch": true,
|
|
17
18
|
"noImplicitReturns": true,
|
|
18
19
|
"noImplicitThis": true,
|
|
19
20
|
"sourceMap": true,
|
|
21
|
+
"strict": false,
|
|
20
22
|
"strictBindCallApply": true,
|
|
21
23
|
"strictNullChecks": true,
|
|
22
24
|
"target": "es6",
|
package/helpers/config.ts
CHANGED
|
@@ -16,8 +16,8 @@ const extensions = [
|
|
|
16
16
|
*
|
|
17
17
|
* @return {boolean}
|
|
18
18
|
*/
|
|
19
|
-
function hasLocalOverride( fileName, inWorkingDirectory = false, ) {
|
|
20
|
-
let hasLocal = false;
|
|
19
|
+
function hasLocalOverride( fileName: string, inWorkingDirectory = false, ) {
|
|
20
|
+
let hasLocal: boolean = false;
|
|
21
21
|
const packageConfig = getPackageConfig();
|
|
22
22
|
try {
|
|
23
23
|
if ( inWorkingDirectory ) {
|
|
@@ -61,7 +61,7 @@ function hasLocalOverride( fileName, inWorkingDirectory = false, ) {
|
|
|
61
61
|
*
|
|
62
62
|
* @return {Object}
|
|
63
63
|
*/
|
|
64
|
-
function getConfig( fileName ) {
|
|
64
|
+
export function getConfig( fileName: string ) {
|
|
65
65
|
const packageConfig = getPackageConfig();
|
|
66
66
|
let mergedConfig = require( '../config/' + fileName );
|
|
67
67
|
mergedConfig = {...mergedConfig, ...getExtensionsConfig( fileName, mergedConfig )};
|
|
@@ -89,8 +89,8 @@ function getConfig( fileName ) {
|
|
|
89
89
|
*
|
|
90
90
|
* @return {Object}
|
|
91
91
|
*/
|
|
92
|
-
function getExtensionsConfig( fileName, defaultConfig ) {
|
|
93
|
-
let mergedConfig = {};
|
|
92
|
+
function getExtensionsConfig( fileName: string, defaultConfig: Record<string, any> ) {
|
|
93
|
+
let mergedConfig: Record<string, any> = {};
|
|
94
94
|
extensions.forEach( extension => {
|
|
95
95
|
try {
|
|
96
96
|
const extensionConfig = require( extension + '/config/' + fileName );
|
|
@@ -173,6 +173,10 @@ const getDefaultBrowsersList = () => {
|
|
|
173
173
|
return false;
|
|
174
174
|
};
|
|
175
175
|
|
|
176
|
+
/**
|
|
177
|
+
* @notice This module must remain CommonJS for use with Jest.
|
|
178
|
+
* It is loaded before TS is loaded by Jest.
|
|
179
|
+
*/
|
|
176
180
|
module.exports = {
|
|
177
181
|
getBrowsersList,
|
|
178
182
|
getConfig,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import {checkModules} from 'are-you-es5';
|
|
2
|
+
import {getBabelLoaderIgnoreRegex} from 'are-you-es5/dist/babel-loader-regex-builder';
|
|
3
3
|
const config = require( './package-config' );
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -13,15 +13,11 @@ const config = require( './package-config' );
|
|
|
13
13
|
*
|
|
14
14
|
* @return {RegExp}
|
|
15
15
|
*/
|
|
16
|
-
function getBabelExcludeRegex() {
|
|
17
|
-
const nonES5 =
|
|
16
|
+
export function getBabelExcludeRegex() {
|
|
17
|
+
const nonES5 = checkModules( {} );
|
|
18
18
|
// Support specifying additional es5Modules in package.json.
|
|
19
|
-
const regex =
|
|
19
|
+
const regex = getBabelLoaderIgnoreRegex( [ ...nonES5.es6Modules, ...config.es6Modules ] );
|
|
20
20
|
|
|
21
21
|
// We must strip off the leading and trailing '/'.
|
|
22
22
|
return new RegExp( regex.replace( /^\/|\/$/g, '' ) );
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
module.exports = {
|
|
26
|
-
getBabelExcludeRegex,
|
|
27
|
-
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const {resolve} = require( 'path' );
|
|
2
2
|
import {realpathSync} from 'fs';
|
|
3
3
|
|
|
4
4
|
const workingDirectory = realpathSync( process.cwd() );
|
|
@@ -30,8 +30,7 @@ try {
|
|
|
30
30
|
export function getPackageConfig() {
|
|
31
31
|
return packageConfig;
|
|
32
32
|
}
|
|
33
|
+
|
|
33
34
|
packageConfig.getPackageConfig = getPackageConfig;
|
|
34
35
|
|
|
35
|
-
// Leaving old export structure for backwards compatibility.
|
|
36
|
-
// @todo Remove in favor of default export in version 11.
|
|
37
36
|
module.exports = packageConfig;
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lipemat/js-boilerplate",
|
|
3
|
-
"version": "10.4.0-beta.
|
|
3
|
+
"version": "10.4.0-beta.4",
|
|
4
4
|
"description": "Dependencies and scripts for a no config JavaScript app",
|
|
5
5
|
"author": "Mat Lipe",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"type": "commonjs",
|
|
8
7
|
"engines": {
|
|
9
8
|
"node": ">=16.14.2"
|
|
10
9
|
},
|
package/scripts/test.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const {resolve: pathResolve} = require( 'path' );
|
|
2
|
+
const {existsSync} = require( 'fs' );
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import {getPackageConfig} from '../helpers/package-config';
|
|
5
|
+
|
|
6
|
+
const packageConfig = getPackageConfig();
|
|
5
7
|
|
|
6
8
|
const possibleConfig = [
|
|
7
9
|
// @todo Remove pulling from the root on next major release.
|
|
8
|
-
|
|
10
|
+
pathResolve( packageConfig.workingDirectory + '/jest.config.ts' ),
|
|
11
|
+
pathResolve( packageConfig.workingDirectory + '/jest.config.js' ),
|
|
9
12
|
|
|
10
13
|
// New location.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
].filter(
|
|
14
|
+
pathResolve( packageConfig.workingDirectory + '/jest/jest.config.ts' ),
|
|
15
|
+
pathResolve( packageConfig.workingDirectory + '/jest/jest.config.js' ),
|
|
16
|
+
].filter( existsSync );
|
|
14
17
|
|
|
15
18
|
if ( possibleConfig.length < 1 ) {
|
|
16
19
|
throw new Error( 'You must have a `jest.config.[tj]s` file in the root of your project or in the `jest` folder.' );
|
package/tsconfig.json
CHANGED
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
"$schema": "https://json.schemastore.org/tsconfig",
|
|
4
4
|
"display": "JS Boilerplate",
|
|
5
5
|
"include": [
|
|
6
|
+
"jest.config.js",
|
|
7
|
+
"jest.config.ts",
|
|
6
8
|
"bin/**/*",
|
|
7
9
|
"config/**/*",
|
|
8
10
|
"helpers/**/*",
|
|
9
11
|
"lib/**/*",
|
|
10
|
-
"scripts/**/*"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"module": "CommonJS"
|
|
15
|
-
}
|
|
12
|
+
"scripts/**/*",
|
|
13
|
+
"tests/**/*",
|
|
14
|
+
]
|
|
16
15
|
}
|
package/config/jest.config.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Kept here for backward compatibility.
|
|
3
|
-
*
|
|
4
|
-
* @deprecated
|
|
5
|
-
*
|
|
6
|
-
* @todo Remove on next major release.
|
|
7
|
-
*
|
|
8
|
-
* @see jest.config.ts
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// Necessary because some of the boilerplate code is written in TypeScript.
|
|
12
|
-
require( 'ts-node/register' );
|
|
13
|
-
|
|
14
|
-
const path = require( 'path' );
|
|
15
|
-
const packageConfig = require( '../helpers/package-config.ts' );
|
|
16
|
-
const fs = require( 'fs' );
|
|
17
|
-
|
|
18
|
-
const babelConfig = require( '../helpers/config.ts' ).getConfig( 'babel.config' );
|
|
19
|
-
delete babelConfig.cacheDirectory;
|
|
20
|
-
|
|
21
|
-
let jestConfig = {
|
|
22
|
-
globals: {
|
|
23
|
-
__TEST__: true,
|
|
24
|
-
},
|
|
25
|
-
moduleNameMapper: {
|
|
26
|
-
'\\.(pcss|less|css)$': 'identity-obj-proxy',
|
|
27
|
-
'is-plain-obj': 'identity-obj-proxy',
|
|
28
|
-
uuid: 'identity-obj-proxy',
|
|
29
|
-
},
|
|
30
|
-
roots: [
|
|
31
|
-
'./tests',
|
|
32
|
-
],
|
|
33
|
-
testEnvironment: 'jsdom',
|
|
34
|
-
testEnvironmentOptions: {
|
|
35
|
-
url: packageConfig.url,
|
|
36
|
-
},
|
|
37
|
-
transform: {
|
|
38
|
-
'^.+\\.[tj]sx?$': [ 'babel-jest', babelConfig ],
|
|
39
|
-
},
|
|
40
|
-
setupFilesAfterEnv: [
|
|
41
|
-
path.resolve( packageConfig.workingDirectory, 'tests/setup.js' ),
|
|
42
|
-
path.resolve( packageConfig.workingDirectory, 'tests/setup.ts' ),
|
|
43
|
-
path.resolve( packageConfig.workingDirectory, 'jest/setup.ts' ),
|
|
44
|
-
].filter( fs.existsSync ),
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Allows overriding configurations in the project `/config/jest.config.js` file.
|
|
49
|
-
* We don't actually need to do this because `jest.config.[tj]s` in the project root
|
|
50
|
-
* is already an override of this file, but we support it anyway to keep things consistent.
|
|
51
|
-
*/
|
|
52
|
-
try {
|
|
53
|
-
const localConfig = require( path.resolve( packageConfig.workingDirectory + '/config', 'jest.config.js' ) );
|
|
54
|
-
jestConfig = {...jestConfig, ...localConfig};
|
|
55
|
-
} catch ( e ) {
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
module.exports = jestConfig;
|