Skip to content
Snippets Groups Projects
Commit df0ba574 authored by Jure's avatar Jure
Browse files

Bring over a commit that brings jest testing to all packages

parent 4430983e
No related branches found
No related tags found
No related merge requests found
Showing
with 80 additions and 17 deletions
...@@ -26,11 +26,29 @@ ...@@ -26,11 +26,29 @@
}, },
"scripts": { "scripts": {
"clean": "lerna clean", "clean": "lerna clean",
"test": "lerna run test", "test": "jest",
"lint": "npm run lint:js && npm run lint:style", "lint": "npm run lint:js && npm run lint:style",
"lint:js": "eslint 'packages/**/*.{js,jsx}'", "lint:js": "eslint 'packages/**/*.{js,jsx}'",
"lint:style": "stylelint 'packages/**/*.{css,scss}'", "lint:style": "stylelint 'packages/**/*.{css,scss}'",
"precommit": "lint-staged" "precommit": "lint-staged"
}, },
"jest": {
"collectCoverage": true,
"collectCoverageFrom": [
"packages/cli/src/*.js",
"packages/cli/cli/*.js",
"client/src/**/*.{js,jsx}",
"components/**/*.{js,jsx}",
"db-manager/src/**/*.js",
"logger/src/**/*.js",
"server/src/**/*.js",
"sse/lib/**/*.js",
"theme-plugin/*.js",
"ui/src/**/*.{js,jsx}",
"!**/*.test.{js,jsx}",
"!**/node_modules/**"
],
"projects": ["packages/*"]
},
"workspaces": ["packages/*", "packages/components/packages/*"] "workspaces": ["packages/*", "packages/components/packages/*"]
} }
...@@ -43,13 +43,14 @@ ...@@ -43,13 +43,14 @@
"nsp": "^2.8.1" "nsp": "^2.8.1"
}, },
"jest": { "jest": {
"testMatch": ["**/test/*.js", "**/test/cli/*.js"], "testMatch": ["<rootDir>/test/*.test.js", "<rootDir>/test/cli/*.test.js"],
"testPathIgnorePatterns": ["<rootDir>/build/"], "testPathIgnorePatterns": ["<rootDir>/build/"],
"collectCoverage": true, "collectCoverage": true,
"collectCoverageFrom": ["src/*.js", "cli/*.js"], "collectCoverageFrom": ["src/*.js", "cli/*.js"],
"modulePaths": ["<rootDir>/node_modules"], "modulePaths": ["<rootDir>/node_modules"],
"testEnvironment": "node", "testEnvironment": "node",
"unmockedModulePathPatterns": ["/src/models"], "unmockedModulePathPatterns": ["/src/models"],
"setupTestFrameworkScriptFile": "<rootDir>/test/jest-setup.js",
"verbose": true "verbose": true
} }
} }
...@@ -24,9 +24,7 @@ const writeSpy = fs.writeJsonSync ...@@ -24,9 +24,7 @@ const writeSpy = fs.writeJsonSync
describe('add', () => { describe('add', () => {
beforeAll(() => { beforeAll(() => {
process.chdir( process.chdir(path.dirname(require.resolve('@pubsweet/starter')))
path.join(__dirname, '..', '..', 'node_modules', '@pubsweet', 'starter'),
)
}) })
beforeEach(() => { beforeEach(() => {
......
File moved
...@@ -24,9 +24,7 @@ const writeSpy = fs.writeJsonSync ...@@ -24,9 +24,7 @@ const writeSpy = fs.writeJsonSync
describe('remove', () => { describe('remove', () => {
beforeAll(() => { beforeAll(() => {
process.chdir( process.chdir(path.dirname(require.resolve('@pubsweet/starter')))
path.join(__dirname, '..', '..', 'node_modules', '@pubsweet', 'starter'),
)
}) })
beforeEach(() => { beforeEach(() => {
......
...@@ -3,7 +3,7 @@ const { spawn } = require('child_process') ...@@ -3,7 +3,7 @@ const { spawn } = require('child_process')
const path = require('path') const path = require('path')
const reduce = require('lodash/fp/reduce').convert({ cap: false }) const reduce = require('lodash/fp/reduce').convert({ cap: false })
const pubsweet = path.resolve('bin/pubsweet.js') const pubsweet = path.resolve(__dirname, '..', '..', 'bin', 'pubsweet.js')
const formatOpts = reduce( const formatOpts = reduce(
(acc, value, key) => acc.concat(`--${key}`, value), (acc, value, key) => acc.concat(`--${key}`, value),
...@@ -41,6 +41,7 @@ const runCommandAsync = ({ args, options, cwd, nodeConfig, stdio }) => ...@@ -41,6 +41,7 @@ const runCommandAsync = ({ args, options, cwd, nodeConfig, stdio }) =>
stdio, stdio,
env: getEnvWithConfig(nodeConfig), env: getEnvWithConfig(nodeConfig),
shell: true, shell: true,
detached: true,
}) })
module.exports = { module.exports = {
......
...@@ -18,6 +18,18 @@ const nodeConfig = { ...@@ -18,6 +18,18 @@ const nodeConfig = {
dbPath, dbPath,
adapter: 'leveldb', adapter: 'leveldb',
}, },
// TODO: Remove this once version of server that handles
// undefined app validations is released.
validations: 'path',
authsome: {
mode: 'authsome/src/modes/blog',
},
pubsweet: {
components: [],
},
'pubsweet-client': {
theme: 'PepperTheme',
},
} }
const dbOptions = { const dbOptions = {
...@@ -155,11 +167,17 @@ describe('CLI: integration test', () => { ...@@ -155,11 +167,17 @@ describe('CLI: integration test', () => {
app.stdout.on('data', async data => { app.stdout.on('data', async data => {
console.log('stdout:', data.toString()) console.log('stdout:', data.toString())
if (data.toString().includes('App is listening')) { if (data.toString().includes('App is listening')) {
const result = await fetch('http://localhost:4000') const result = await fetch('http://localhost:3000')
expect(result.status).toBe(200) expect(result.status).toBe(200)
done() console.log('Killing the app')
process.kill(-app.pid)
} }
}) })
app.on('close', (code, signal) => {
console.log(`App killed ${signal}`)
done()
})
}) })
}) })
}) })
const path = require('path')
process.env.NODE_CONFIG_DIR = path.resolve(__dirname, '..', 'config')
process.cwd = () => path.resolve(__dirname, '..')
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
"jest": { "jest": {
"testRegex": "/test/.+test.jsx?$", "testRegex": "/test/.+test.jsx?$",
"collectCoverage": true, "collectCoverage": true,
"setupTestFrameworkScriptFile": "<rootDir>/test/jest-setup.js",
"collectCoverageFrom": ["src/**/*.{js,jsx}"], "collectCoverageFrom": ["src/**/*.{js,jsx}"],
"globals": { "globals": {
"window": {} "window": {}
......
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import path from 'path'
Enzyme.configure({ adapter: new Adapter() })
process.env.NODE_CONFIG_DIR = path.resolve(__dirname, '..', 'config')
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
"\\.s?css$": "identity-obj-proxy" "\\.s?css$": "identity-obj-proxy"
}, },
"transformIgnorePatterns": ["/node_modules/(?!pubsweet)"], "transformIgnorePatterns": ["/node_modules/(?!pubsweet)"],
"testPathIgnorePatterns": ["/node_modules", "config/"] "testPathIgnorePatterns": ["/node_modules", "config/"],
"setupTestFrameworkScriptFile": "<rootDir>/test/jest-setup.js"
} }
} }
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import path from 'path'
Enzyme.configure({ adapter: new Adapter() })
process.env.NODE_CONFIG_DIR = path.resolve(__dirname, '..', 'config')
...@@ -19,10 +19,10 @@ ...@@ -19,10 +19,10 @@
"npm": ">=3.0.0" "npm": ">=3.0.0"
}, },
"jest": { "jest": {
"testMatch": ["**/test/**/*.js"], "testMatch": ["**/test/**/*.test.js"],
"collectCoverage": true, "collectCoverage": true,
"collectCoverageFrom": ["src/**/*.js"], "collectCoverageFrom": ["src/**/*.js"],
"modulePaths": ["<rootDir>/node_modules"], "setupTestFrameworkScriptFile": "<rootDir>/test/jest-setup.js",
"testEnvironment": "node", "testEnvironment": "node",
"verbose": true "verbose": true
}, },
......
const path = require('path')
process.env.NODE_CONFIG_DIR = path.resolve(__dirname, '..', 'config')
...@@ -25,12 +25,13 @@ ...@@ -25,12 +25,13 @@
"winston": "^2.3.1" "winston": "^2.3.1"
}, },
"jest": { "jest": {
"testMatch": ["**/test/**/*.js"], "testMatch": ["**/test/**/*test.js"],
"collectCoverage": true, "collectCoverage": true,
"collectCoverageFrom": ["src/**/*.js"], "collectCoverageFrom": ["src/**/*.js"],
"modulePaths": ["<rootDir>/node_modules"], "modulePaths": ["<rootDir>/node_modules"],
"testEnvironment": "node", "testEnvironment": "node",
"verbose": true "verbose": true,
"setupTestFrameworkScriptFile": "<rootDir>/test/jest-setup.js"
}, },
"dependencies": { "dependencies": {
"config": "^1.26.2", "config": "^1.26.2",
......
const path = require('path')
process.env.NODE_CONFIG_DIR = path.resolve(__dirname, '..', 'config')
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
"testEnvironment": "node", "testEnvironment": "node",
"testRegex": "/test/.*_test.js$", "testRegex": "/test/.*_test.js$",
"collectCoverage": true, "collectCoverage": true,
"collectCoverageFrom": ["src/**/*.js"] "collectCoverageFrom": ["src/**/*.js"],
"setupTestFrameworkScriptFile": "<rootDir>/test/jest-setup.js"
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment