From 3bca612ac163a87e425e89a0a04e8e4c763637be Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Thu, 16 Jan 2020 14:04:07 +0100 Subject: [PATCH 1/6] Refactor tests and add codecov Signed-off-by: Alexandre Bodin --- .travis.yml | 5 +++-- jest.config.e2e.js | 3 +-- jest.config.js | 12 ++---------- package.json | 2 +- .../strapi-plugin-content-manager/package.json | 3 --- .../jest.config.unit.js | 3 --- .../package.json | 3 --- packages/strapi-utils/package.json | 3 --- packages/strapi/lib/core/__tests__/fs.test.js | 18 ++++++++---------- packages/strapi/package.json | 1 - 10 files changed, 15 insertions(+), 38 deletions(-) delete mode 100644 packages/strapi-plugin-content-type-builder/jest.config.unit.js diff --git a/.travis.yml b/.travis.yml index f09ac35e05..2eeb6dfb8f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,6 +44,7 @@ install_mongo: &install_mongo before_script: - yarn build - yarn global add -g wait-on + - yarn global add codecov jobs: include: @@ -56,8 +57,8 @@ jobs: name: 'Lint / Unit Tests ' script: - yarn run -s lint - - yarn run -s test:unit - - yarn run -s test:front + - yarn run -s test:unit && codecov -F unit + - yarn run -s test:front && codecov -F front - <<: *e2e_tests name: 'E2E Postgresql' diff --git a/jest.config.e2e.js b/jest.config.e2e.js index 279ca040c8..fe0d8a2421 100644 --- a/jest.config.e2e.js +++ b/jest.config.e2e.js @@ -1,6 +1,5 @@ module.exports = { - name: 'setup', - displayName: 'Setup', + name: 'Api integration tests', testMatch: ['**/?(*.)+(spec|test).e2e.js'], testEnvironment: 'node', coveragePathIgnorePatterns: [ diff --git a/jest.config.js b/jest.config.js index 8de85dea19..8318124e24 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,13 +1,5 @@ module.exports = { - name: 'setup', - displayName: 'Setup', - testMatch: ['**/test/?(*.)+(spec|test).js'], - testPathIgnorePatterns: ['/packages/'], - coveragePathIgnorePatterns: [ - '/dist/', - '/node_modules/', - '/out-tsc/', - '/test/', - ], + name: 'Unit test', + testMatch: ['**/packages/**/__tests__/?(*.)+(spec|test).js'], transform: {}, }; diff --git a/package.json b/package.json index 586cf5b034..4fbf56343a 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "test:front:watch": "cross-env NODE_ENV=test jest --config ./jest.config.front.js --watchAll", "test:front:update": "cross-env NODE_ENV=test jest --config ./jest.config.front.js --u", "test:snyk": "snyk test", - "test:unit": "lerna exec -- npm run test -s", + "test:unit": "jest --verbose", "test:e2e": "FORCE_COLOR=true jest --config jest.config.e2e.js --runInBand --verbose --forceExit --detectOpenHandles", "test:generate-app": "node test/createTestApp.js", "test:start-app": "node test/startTestApp.js" diff --git a/packages/strapi-plugin-content-manager/package.json b/packages/strapi-plugin-content-manager/package.json index aaac165529..ebfbaf46b6 100644 --- a/packages/strapi-plugin-content-manager/package.json +++ b/packages/strapi-plugin-content-manager/package.json @@ -8,9 +8,6 @@ "description": "content-manager.plugin.description", "required": true }, - "scripts": { - "test": "jest services" - }, "dependencies": { "classnames": "^2.2.6", "codemirror": "^5.46.0", diff --git a/packages/strapi-plugin-content-type-builder/jest.config.unit.js b/packages/strapi-plugin-content-type-builder/jest.config.unit.js deleted file mode 100644 index ee272ed062..0000000000 --- a/packages/strapi-plugin-content-type-builder/jest.config.unit.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - testMatch: ['**/__tests__/?(*.)+(spec|test).js'], -}; diff --git a/packages/strapi-plugin-content-type-builder/package.json b/packages/strapi-plugin-content-type-builder/package.json index f18a9c5726..3d72835601 100644 --- a/packages/strapi-plugin-content-type-builder/package.json +++ b/packages/strapi-plugin-content-type-builder/package.json @@ -7,9 +7,6 @@ "icon": "paint-brush", "description": "content-type-builder.plugin.description" }, - "scripts": { - "test": "jest --verbose --config=jest.config.unit.js" - }, "dependencies": { "@sindresorhus/slugify": "^0.9.1", "classnames": "^2.2.6", diff --git a/packages/strapi-utils/package.json b/packages/strapi-utils/package.json index 909f179efa..4c02160f1d 100644 --- a/packages/strapi-utils/package.json +++ b/packages/strapi-utils/package.json @@ -14,9 +14,6 @@ "lib": "./lib" }, "main": "./lib", - "scripts": { - "test": "jest" - }, "dependencies": { "date-fns": "^2.8.1", "knex": "^0.16.5", diff --git a/packages/strapi/lib/core/__tests__/fs.test.js b/packages/strapi/lib/core/__tests__/fs.test.js index 55e6029822..c2718a5c1a 100644 --- a/packages/strapi/lib/core/__tests__/fs.test.js +++ b/packages/strapi/lib/core/__tests__/fs.test.js @@ -1,6 +1,7 @@ const fs = require('../fs'); +const fse = require('fs-extra'); + jest.mock('fs-extra'); -const fsExtra = require('fs-extra'); describe('Strapi fs utils', () => { const strapi = { @@ -22,8 +23,8 @@ describe('Strapi fs utils', () => { await strapiFS.writeAppFile('test', content); - expect(fsExtra.ensureFile).toHaveBeenCalledWith('/tmp/test'); - expect(fsExtra.writeFile).toHaveBeenCalledWith('/tmp/test', content); + expect(fse.ensureFile).toHaveBeenCalledWith('/tmp/test'); + expect(fse.writeFile).toHaveBeenCalledWith('/tmp/test', content); }); test('Normalize the path to avoid relative access to folders in parent directories', async () => { @@ -33,8 +34,8 @@ describe('Strapi fs utils', () => { await strapiFS.writeAppFile('../../test', content); - expect(fsExtra.ensureFile).toHaveBeenCalledWith('/tmp/test'); - expect(fsExtra.writeFile).toHaveBeenCalledWith('/tmp/test', content); + expect(fse.ensureFile).toHaveBeenCalledWith('/tmp/test'); + expect(fse.writeFile).toHaveBeenCalledWith('/tmp/test', content); }); test('Works with array path', async () => { @@ -44,11 +45,8 @@ describe('Strapi fs utils', () => { await strapiFS.writeAppFile(['test', 'sub', 'path'], content); - expect(fsExtra.ensureFile).toHaveBeenCalledWith('/tmp/test/sub/path'); - expect(fsExtra.writeFile).toHaveBeenCalledWith( - '/tmp/test/sub/path', - content - ); + expect(fse.ensureFile).toHaveBeenCalledWith('/tmp/test/sub/path'); + expect(fse.writeFile).toHaveBeenCalledWith('/tmp/test/sub/path', content); }); }); diff --git a/packages/strapi/package.json b/packages/strapi/package.json index 2ae727b06f..6697fae40e 100644 --- a/packages/strapi/package.json +++ b/packages/strapi/package.json @@ -61,7 +61,6 @@ "strapi-utils": "3.0.0-beta.18.4" }, "scripts": { - "test": "jest --verbose", "postinstall": "node lib/utils/success.js" }, "author": { From 0674bbd95c9bc19806553774fbde18bf90bc9d00 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Thu, 16 Jan 2020 14:30:29 +0100 Subject: [PATCH 2/6] Clear coverage after sending Signed-off-by: Alexandre Bodin --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2eeb6dfb8f..68ff2529ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,8 +57,8 @@ jobs: name: 'Lint / Unit Tests ' script: - yarn run -s lint - - yarn run -s test:unit && codecov -F unit - - yarn run -s test:front && codecov -F front + - yarn run -s test:unit && codecov -c -F unit + - yarn run -s test:front && codecov -c -F front - <<: *e2e_tests name: 'E2E Postgresql' From 3f55adc34e4b0f32091b888da0dd057d8afcc19b Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Thu, 16 Jan 2020 14:51:55 +0100 Subject: [PATCH 3/6] Improve publish script Signed-off-by: Alexandre Bodin --- scripts/publish.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/publish.sh b/scripts/publish.sh index 384f2421a6..45b7f91179 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Force start from root folder cd "$(dirname "$0")/.." @@ -6,7 +8,7 @@ set -e version="" echo "Please enter the version you want to publish" -read version +read -r version # publish packages ./node_modules/.bin/lerna publish --no-push --dist-tag beta --exact "$version" From fbfd61122dba3851403c3b5c773c7963a3fe6453 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Thu, 16 Jan 2020 15:03:13 +0100 Subject: [PATCH 4/6] Fix codecov option Signed-off-by: Alexandre Bodin --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 68ff2529ed..a206743ea9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,8 +57,8 @@ jobs: name: 'Lint / Unit Tests ' script: - yarn run -s lint - - yarn run -s test:unit && codecov -c -F unit - - yarn run -s test:front && codecov -c -F front + - yarn run -s test:unit && codecov -C -F unit + - yarn run -s test:front && codecov -C -F front - <<: *e2e_tests name: 'E2E Postgresql' From 9d8e285c55e92642f9405ff952c5c57abbdd9413 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Thu, 16 Jan 2020 15:16:46 +0100 Subject: [PATCH 5/6] Add --coverage option Signed-off-by: Alexandre Bodin --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a206743ea9..85760cab6b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,7 +57,7 @@ jobs: name: 'Lint / Unit Tests ' script: - yarn run -s lint - - yarn run -s test:unit && codecov -C -F unit + - yarn run -s test:unit --coverage && codecov -C -F unit - yarn run -s test:front && codecov -C -F front - <<: *e2e_tests From 9eca5aa14ed4f250fb6f18cacdab5a91257547cb Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Thu, 16 Jan 2020 16:50:43 +0100 Subject: [PATCH 6/6] Fix typo Signed-off-by: Alexandre Bodin --- jest.config.e2e.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jest.config.e2e.js b/jest.config.e2e.js index fe0d8a2421..03363cef94 100644 --- a/jest.config.e2e.js +++ b/jest.config.e2e.js @@ -1,5 +1,5 @@ module.exports = { - name: 'Api integration tests', + name: 'API integration tests', testMatch: ['**/?(*.)+(spec|test).e2e.js'], testEnvironment: 'node', coveragePathIgnorePatterns: [