Skip to content

Commit

Permalink
Expand nx usage and migrate logger to ts (strapi#15957)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebodin authored Mar 22, 2023
1 parent edc2bdc commit aaeb988
Show file tree
Hide file tree
Showing 188 changed files with 1,978 additions and 1,704 deletions.
18 changes: 0 additions & 18 deletions .eslintignore

This file was deleted.

19 changes: 0 additions & 19 deletions .eslintrc.back.type-definitions.js

This file was deleted.

42 changes: 0 additions & 42 deletions .eslintrc.js

This file was deleted.

3 changes: 3 additions & 0 deletions .github/actions/check-pr-status/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
.eslintrc.js
dist/
4 changes: 4 additions & 0 deletions .github/actions/check-pr-status/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['custom/back'],
};
3 changes: 2 additions & 1 deletion .github/actions/check-pr-status/__tests__/action.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const action = require('../index');
'use strict';

jest.mock('@actions/github');
jest.mock('@actions/core');

const github = require('@actions/github');
const core = require('@actions/core');
const action = require('../index');

test.each(action.BLOCKING_LABELS)('Test blocking labels %s', async (label) => {
github.context = {
Expand Down
10 changes: 2 additions & 8 deletions .github/actions/check-pr-status/dist/index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .github/actions/check-pr-status/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const core = require('@actions/core');
const github = require('@actions/github');

Expand Down
9 changes: 6 additions & 3 deletions .github/actions/check-pr-status/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
"private": true,
"scripts": {
"build": "NODE_ENV=production ncc build index.js -o dist --minify",
"watch": "NODE_ENV=production ncc build index.js -w -o dist --minify"
"watch": "NODE_ENV=production ncc build index.js -w -o dist --minify",
"lint": "eslint ."
},
"devDependencies": {
"dependencies": {
"@actions/core": "1.10.0",
"@actions/github": "5.1.1",
"@actions/github": "5.1.1"
},
"devDependencies": {
"@vercel/ncc": "0.36.1"
}
}
39 changes: 14 additions & 25 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ concurrency:

permissions:
contents: read # to fetch code (actions/checkout)
actions: read

jobs:
lint:
Expand All @@ -25,19 +26,19 @@ jobs:
node: [14, 16, 18]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/yarn.lock') }}

- uses: nrwl/nx-set-shas@v3
- run: yarn install --frozen-lockfile
- name: Build TypeScript packages # for lint we need to build ts, for rules checking if paths exist
run: yarn build:ts
- name: Run lint
run: yarn run -s lint
run: yarn nx affected --target=lint --parallel --nx-ignore-cycles

unit_back:
name: 'unit_back (node: ${{ matrix.node }})'
Expand All @@ -48,25 +49,19 @@ jobs:
node: [14, 16, 18]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/yarn.lock') }}

- uses: nrwl/nx-set-shas@v3
- run: yarn install --frozen-lockfile
- name: Build TypeScript packages # for unit tests we need to build ts, for finding and mocking ts packages
run: yarn build:ts
- name: Run tests
run: yarn run -s test:unit --coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage
flags: back,unit_back
run: yarn nx affected --target=test:unit --nx-ignore-cycles

unit_front:
name: 'unit_front (node: ${{ matrix.node }})'
Expand All @@ -77,25 +72,19 @@ jobs:
node: [18]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/yarn.lock') }}

- uses: nrwl/nx-set-shas@v3
- run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Run test
run: yarn run -s test:front --coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage
flags: front,unit_front
run: yarn nx affected --target=test:front --nx-ignore-cycles

build:
name: 'build (node: ${{ matrix.node }})'
Expand All @@ -115,7 +104,7 @@ jobs:
key: ${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/yarn.lock') }}
- run: yarn install --frozen-lockfile
- name: Build
run: yarn build --scope @strapi/admin --scope @strapi/helper-plugin
run: yarn build --projects=@strapi/admin,@strapi/helper-plugin

api_ce_pg:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ $RECYCLE.BIN/
*#
.idea
nbproject
.vscode/
.eslintcache


Expand Down Expand Up @@ -135,6 +134,8 @@ schema.graphql
# Visual Studio Code
############################

.vscode/
!.vscode/settings.json
front-workspace.code-workspace
.yarn
.yarnrc
3 changes: 2 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no lint-staged
yarn lint-staged
yarn nx affected:lint --uncommitted --nx-ignore-cycles
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eslint.workingDirectories": [{ "mode": "auto" }]
}
85 changes: 85 additions & 0 deletions jest-preset.front.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'use strict';

const path = require('path');

const IS_EE = process.env.IS_EE === 'true';

const moduleNameMapper = {
'.*\\.(css|less|styl|scss|sass)$': path.join(
__dirname,
'packages/admin-test-utils/lib/mocks/cssModule.js'
),
'.*\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|ico)$':
path.join(__dirname, 'packages/admin-test-utils/lib/mocks/image.js'),
'^ee_else_ce(/.*)$': IS_EE
? [
path.join(__dirname, 'packages/core/admin/ee/admin$1'),
path.join(__dirname, 'packages/core/content-manager/ee/admin/src$1'),
path.join(__dirname, 'packages/core/content-type-builder/ee/admin/src$1'),
path.join(__dirname, 'packages/core/upload/ee/admin/src$1'),
path.join(__dirname, 'packages/core/email/ee/admin/src$1'),
path.join(__dirname, 'packages/plugins/*/ee/admin/src$1'),
]
: [
path.join(__dirname, 'packages/core/admin/admin/src$1'),
path.join(__dirname, 'packages/core/content-manager/admin/src$1'),
path.join(__dirname, 'packages/core/content-type-builder/admin/src$1'),
path.join(__dirname, 'packages/core/upload/admin/src$1'),
path.join(__dirname, 'packages/core/email/admin/src$1'),
path.join(__dirname, 'packages/plugins/*/admin/src$1'),
],
};

module.exports = {
rootDir: __dirname,
moduleNameMapper,
testPathIgnorePatterns: ['/node_modules/', '__tests__'],
globalSetup: path.join(__dirname, 'test/config/front/global-setup.js'),
setupFiles: [
path.join(__dirname, 'packages/admin-test-utils/lib/setup/test-bundler.js'),
path.join(__dirname, 'packages/admin-test-utils/lib/mocks/fetch.js'),
path.join(__dirname, 'packages/admin-test-utils/lib/mocks/LocalStorageMock.js'),
path.join(__dirname, 'packages/admin-test-utils/lib/mocks/IntersectionObserver.js'),
path.join(__dirname, 'packages/admin-test-utils/lib/mocks/ResizeObserver.js'),
path.join(__dirname, 'packages/admin-test-utils/lib/mocks/windowMatchMedia.js'),
path.join(__dirname, 'packages/admin-test-utils/lib/mocks/mockRangeApi.js'),
],
setupFilesAfterEnv: [
path.join(__dirname, '/packages/admin-test-utils/lib/setup/styled-components.js'),
path.join(__dirname, '/packages/admin-test-utils/lib/setup/strapi.js'),
path.join(__dirname, '/packages/admin-test-utils/lib/setup/prop-types.js'),
],
testEnvironment: 'jsdom',
transform: {
'^.+\\.js$': [
'@swc/jest',
{
env: {
coreJs: '3.28.0',
mode: 'usage',
},

jsc: {
parser: {
jsx: true,
dynamicImport: true,
},
// this should match the minimum supported node.js version
target: 'es2020',
},
},
],
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
path.join(__dirname, 'fileTransformer.js'),
},
transformIgnorePatterns: [
'node_modules/(?!(react-dnd|dnd-core|react-dnd-html5-backend|@strapi/design-system|@strapi/icons|fractional-indexing)/)',
],
testMatch: ['/**/tests/**/?(*.)+(spec|test).[jt]s?(x)'],
testEnvironmentOptions: {
url: 'http://localhost:1337/admin',
},
// Use `jest-watch-typeahead` version 0.6.5. Newest version 1.0.0 does not support jest@26
// Reference: https://github.com/jest-community/jest-watch-typeahead/releases/tag/v1.0.0
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
};
4 changes: 1 addition & 3 deletions jest.base-config.js → jest-preset.unit.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';

module.exports = {
rootDir: __dirname,
setupFilesAfterEnv: ['<rootDir>/test/unit.setup.js'],
setupFilesAfterEnv: [__dirname + '/test/unit.setup.js'],
modulePathIgnorePatterns: ['.cache', 'dist'],
testPathIgnorePatterns: ['.testdata.js', '.test.utils.js'],
// TODO: testMatch should only include files with (test|spec) even within __tests__ so that utilities can be included and ignored there
testMatch: ['/**/__tests__/**/*.[jt]s?(x)'],
// Use `jest-watch-typeahead` version 0.6.5. Newest version 1.0.0 does not support jest@26
// Reference: https://github.com/jest-community/jest-watch-typeahead/releases/tag/v1.0.0
Expand Down
Loading

0 comments on commit aaeb988

Please sign in to comment.