Skip to content

Commit

Permalink
Scripts: Add TypeScript for builds and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Nov 5, 2021
1 parent 098278b commit d41b5eb
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 35 deletions.
115 changes: 105 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"eslint-plugin-eslint-comments": "3.1.2",
"eslint-plugin-import": "2.23.4",
"execa": "4.0.2",
"fast-glob": "2.2.7",
"fast-glob": "3.2.7",
"glob": "7.1.2",
"husky": "7.0.0",
"inquirer": "7.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"check-node-version": "^4.1.0",
"commander": "^4.1.0",
"execa": "^4.0.2",
"fast-glob": "^2.2.7",
"fast-glob": "^3.2.7",
"inquirer": "^7.1.0",
"lodash": "^4.17.21",
"make-dir": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset-default/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ npm install @wordpress/jest-preset-default --save-dev
- `setupFiles` - runs code before each test which sets up global variables required in the testing environment.
- `setupFilesAfterEnv` - runs code which adds improved support for `Console` object and `React` components to the testing framework before each test.
- `snapshotSerializers` - makes it possible to use snapshot tests on `Enzyme` wrappers.
- `testMatch`- includes `/test/` subfolder in addition to the glob patterns Jest uses to detect test files. It detects only test files containing `.js` (or `.ts`) suffix. It doesn't match files with `.spec.js` suffix.
- `testMatch`- includes `/test/` subfolder in addition to the glob patterns Jest uses to detect test files. It detects only test files containing `.js`, `.jsx`, `.ts` and `.tsx` suffix. It doesn't match files with `.spec.js` suffix.
- `timers` - use of [fake timers](https://jestjs.io/docs/en/timer-mocks.html) for functions such as `setTimeout` is enabled.
- `transform` - keeps the default [babel-jest](https://github.com/facebook/jest/tree/HEAD/packages/babel-jest) transformer.
- `verbose` - each individual test won't be reported during the run.
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-preset-default/jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ module.exports = {
],
snapshotSerializers: [ require.resolve( 'enzyme-to-json/serializer.js' ) ],
testMatch: [
'**/__tests__/**/*.[jt]s',
'**/test/*.[jt]s',
'**/?(*.)test.[jt]s',
'**/__tests__/**/*.[jt]s?(x)',
'**/test/*.[jt]s?(x)',
'**/?(*.)test.[jt]s?(x)',
],
testPathIgnorePatterns: [ '/node_modules/', '<rootDir>/vendor/' ],
timers: 'fake',
transform: {
'^.+\\.[jt]sx?$': require.resolve( 'babel-jest' ),
'\\.[jt]sx?$': require.resolve( 'babel-jest' ),
},
};
4 changes: 2 additions & 2 deletions packages/scripts/config/jest-e2e.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const jestE2EConfig = {
],
setupFilesAfterEnv: [ 'expect-puppeteer' ],
testEnvironment: path.join( __dirname, 'jest-environment-puppeteer' ),
testMatch: [ '**/specs/**/*.[jt]s', '**/?(*.)spec.[jt]s' ],
testMatch: [ '**/specs/**/*.[jt]s?(x)', '**/?(*.)spec.[jt]s?(x)' ],
testPathIgnorePatterns: [ '/node_modules/' ],
testRunner: 'jest-circus/runner',
testTimeout: 30000,
};

if ( ! hasBabelConfig() ) {
jestE2EConfig.transform = {
'^.+\\.[jt]sx?$': path.join( __dirname, 'babel-transform' ),
'\\.[jt]sx?$': path.join( __dirname, 'babel-transform' ),
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/config/jest-unit.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const jestUnitConfig = {

if ( ! hasBabelConfig() ) {
jestUnitConfig.transform = {
'^.+\\.[jt]sx?$': path.join( __dirname, 'babel-transform' ),
'\\.[jt]sx?$': path.join( __dirname, 'babel-transform' ),
};
}

Expand Down
28 changes: 13 additions & 15 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const MiniCSSExtractPlugin = require( 'mini-css-extract-plugin' );
const TerserPlugin = require( 'terser-webpack-plugin' );
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
const browserslist = require( 'browserslist' );
const fs = require( 'fs' );
const { sync: glob } = require( 'fast-glob' );
const path = require( 'path' );

/**
Expand Down Expand Up @@ -36,17 +36,14 @@ let entry = {};
if ( process.env.WP_ENTRY ) {
entry = JSON.parse( process.env.WP_ENTRY );
} else {
// By default the script checks if `src/index.js` exists and sets it as an entry point.
// In the future we should add similar handling for `src/script.js` and `src/view.js`.
[ 'index' ].forEach( ( entryName ) => {
const filepath = path.resolve(
process.cwd(),
'src',
`${ entryName }.js`
);
if ( fs.existsSync( filepath ) ) {
entry[ entryName ] = filepath;
}
// The script checks whether standard file names can be detected in the `src` folder,
// and converts all found files to entry points.
const entryFiles = glob( 'src/index.[jt]s?(x)', {
absolute: true,
} );
entryFiles.forEach( ( filepath ) => {
const [ entryName ] = path.basename( filepath ).split( '.' );
entry[ entryName ] = filepath;
} );
}

Expand Down Expand Up @@ -115,6 +112,7 @@ const config = {
alias: {
'lodash-es': 'lodash',
},
extensions: [ '.ts', '.tsx', '...' ],
},
optimization: {
// Only concatenate modules in production, when not analyzing bundles.
Expand Down Expand Up @@ -155,7 +153,7 @@ const config = {
module: {
rules: [
{
test: /\.jsx?$/,
test: /\.(j|t)sx?$/,
exclude: /node_modules/,
use: [
{
Expand Down Expand Up @@ -200,7 +198,7 @@ const config = {
},
{
test: /\.svg$/,
issuer: /\.jsx?$/,
issuer: /\.(j|t)sx?$/,
use: [ '@svgr/webpack', 'url-loader' ],
type: 'javascript/auto',
},
Expand Down Expand Up @@ -259,7 +257,7 @@ if ( ! isProduction ) {
// See: https://webpack.js.org/configuration/devtool/#devtool.
config.devtool = process.env.WP_DEVTOOL || 'source-map';
config.module.rules.unshift( {
test: /\.js$/,
test: /\.(j|t)sx?$/,
exclude: [ /node_modules/ ],
use: require.resolve( 'source-map-loader' ),
enforce: 'pre',
Expand Down
1 change: 1 addition & 0 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"eslint": "^7.17.0",
"eslint-plugin-markdown": "^2.2.0",
"expect-puppeteer": "^4.4.0",
"fast-glob": "^3.2.7",
"filenamify": "^4.2.0",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
Expand Down

0 comments on commit d41b5eb

Please sign in to comment.