Merge pull request #5006 from strapi/chore/test-scripts

Refactor tests and add codecov
This commit is contained in:
Alexandre BODIN 2020-01-16 16:54:55 +01:00 committed by GitHub
commit ff1b249d31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 18 additions and 39 deletions

View File

@ -44,6 +44,7 @@ install_mongo: &install_mongo
before_script: before_script:
- yarn build - yarn build
- yarn global add -g wait-on - yarn global add -g wait-on
- yarn global add codecov
jobs: jobs:
include: include:
@ -56,8 +57,8 @@ jobs:
name: 'Lint / Unit Tests ' name: 'Lint / Unit Tests '
script: script:
- yarn run -s lint - yarn run -s lint
- yarn run -s test:unit - yarn run -s test:unit --coverage && codecov -C -F unit
- yarn run -s test:front - yarn run -s test:front && codecov -C -F front
- <<: *e2e_tests - <<: *e2e_tests
name: 'E2E Postgresql' name: 'E2E Postgresql'

View File

@ -1,6 +1,5 @@
module.exports = { module.exports = {
name: 'setup', name: 'API integration tests',
displayName: 'Setup',
testMatch: ['**/?(*.)+(spec|test).e2e.js'], testMatch: ['**/?(*.)+(spec|test).e2e.js'],
testEnvironment: 'node', testEnvironment: 'node',
coveragePathIgnorePatterns: [ coveragePathIgnorePatterns: [

View File

@ -1,13 +1,5 @@
module.exports = { module.exports = {
name: 'setup', name: 'Unit test',
displayName: 'Setup', testMatch: ['**/packages/**/__tests__/?(*.)+(spec|test).js'],
testMatch: ['**/test/?(*.)+(spec|test).js'],
testPathIgnorePatterns: ['<rootDir>/packages/'],
coveragePathIgnorePatterns: [
'<rootDir>/dist/',
'<rootDir>/node_modules/',
'<rootDir>/out-tsc/',
'<rootDir>/test/',
],
transform: {}, transform: {},
}; };

View File

@ -49,7 +49,7 @@
"test:front:watch": "cross-env NODE_ENV=test jest --config ./jest.config.front.js --watchAll", "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:front:update": "cross-env NODE_ENV=test jest --config ./jest.config.front.js --u",
"test:snyk": "snyk test", "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:e2e": "FORCE_COLOR=true jest --config jest.config.e2e.js --runInBand --verbose --forceExit --detectOpenHandles",
"test:generate-app": "node test/createTestApp.js", "test:generate-app": "node test/createTestApp.js",
"test:start-app": "node test/startTestApp.js" "test:start-app": "node test/startTestApp.js"

View File

@ -8,9 +8,6 @@
"description": "content-manager.plugin.description", "description": "content-manager.plugin.description",
"required": true "required": true
}, },
"scripts": {
"test": "jest services"
},
"dependencies": { "dependencies": {
"classnames": "^2.2.6", "classnames": "^2.2.6",
"codemirror": "^5.46.0", "codemirror": "^5.46.0",

View File

@ -1,3 +0,0 @@
module.exports = {
testMatch: ['**/__tests__/?(*.)+(spec|test).js'],
};

View File

@ -7,9 +7,6 @@
"icon": "paint-brush", "icon": "paint-brush",
"description": "content-type-builder.plugin.description" "description": "content-type-builder.plugin.description"
}, },
"scripts": {
"test": "jest --verbose --config=jest.config.unit.js"
},
"dependencies": { "dependencies": {
"@sindresorhus/slugify": "^0.9.1", "@sindresorhus/slugify": "^0.9.1",
"classnames": "^2.2.6", "classnames": "^2.2.6",

View File

@ -14,9 +14,6 @@
"lib": "./lib" "lib": "./lib"
}, },
"main": "./lib", "main": "./lib",
"scripts": {
"test": "jest"
},
"dependencies": { "dependencies": {
"date-fns": "^2.8.1", "date-fns": "^2.8.1",
"knex": "^0.16.5", "knex": "^0.16.5",

View File

@ -1,6 +1,7 @@
const fs = require('../fs'); const fs = require('../fs');
const fse = require('fs-extra');
jest.mock('fs-extra'); jest.mock('fs-extra');
const fsExtra = require('fs-extra');
describe('Strapi fs utils', () => { describe('Strapi fs utils', () => {
const strapi = { const strapi = {
@ -22,8 +23,8 @@ describe('Strapi fs utils', () => {
await strapiFS.writeAppFile('test', content); await strapiFS.writeAppFile('test', content);
expect(fsExtra.ensureFile).toHaveBeenCalledWith('/tmp/test'); expect(fse.ensureFile).toHaveBeenCalledWith('/tmp/test');
expect(fsExtra.writeFile).toHaveBeenCalledWith('/tmp/test', content); expect(fse.writeFile).toHaveBeenCalledWith('/tmp/test', content);
}); });
test('Normalize the path to avoid relative access to folders in parent directories', async () => { 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); await strapiFS.writeAppFile('../../test', content);
expect(fsExtra.ensureFile).toHaveBeenCalledWith('/tmp/test'); expect(fse.ensureFile).toHaveBeenCalledWith('/tmp/test');
expect(fsExtra.writeFile).toHaveBeenCalledWith('/tmp/test', content); expect(fse.writeFile).toHaveBeenCalledWith('/tmp/test', content);
}); });
test('Works with array path', async () => { test('Works with array path', async () => {
@ -44,11 +45,8 @@ describe('Strapi fs utils', () => {
await strapiFS.writeAppFile(['test', 'sub', 'path'], content); await strapiFS.writeAppFile(['test', 'sub', 'path'], content);
expect(fsExtra.ensureFile).toHaveBeenCalledWith('/tmp/test/sub/path'); expect(fse.ensureFile).toHaveBeenCalledWith('/tmp/test/sub/path');
expect(fsExtra.writeFile).toHaveBeenCalledWith( expect(fse.writeFile).toHaveBeenCalledWith('/tmp/test/sub/path', content);
'/tmp/test/sub/path',
content
);
}); });
}); });

View File

@ -61,7 +61,6 @@
"strapi-utils": "3.0.0-beta.18.4" "strapi-utils": "3.0.0-beta.18.4"
}, },
"scripts": { "scripts": {
"test": "jest --verbose",
"postinstall": "node lib/utils/success.js" "postinstall": "node lib/utils/success.js"
}, },
"author": { "author": {

View File

@ -1,3 +1,5 @@
#!/bin/bash
# Force start from root folder # Force start from root folder
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
@ -6,7 +8,7 @@ set -e
version="" version=""
echo "Please enter the version you want to publish" echo "Please enter the version you want to publish"
read version read -r version
# publish packages # publish packages
./node_modules/.bin/lerna publish --no-push --dist-tag beta --exact "$version" ./node_modules/.bin/lerna publish --no-push --dist-tag beta --exact "$version"