diff --git a/.gitignore b/.gitignore index 755cb40..48348c0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ node_modules/ .pnp.js # testing -/coverage +coverage # production lib diff --git a/.travis.yml b/.travis.yml index 77eaa24..ee605b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,11 @@ language: node_js node_js: - - 'node' + - "8" before_script: - - cd minimal_redux_poc - npm install + - cd packages/mirador3-core + - npm install + - cd ../mirador3-app + - cd ../.. + - lerna run build + - lerna run test diff --git a/README.md b/README.md index b887ac2..40734aa 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,27 @@ # research-and-demos Proofs of concept for Mirador 3 -1. git clone the repository -2. Navigate to the relevant POC, for example, `cd minimal_redux_poc` -3. Follow the README for that POC. +## lerna +lerna helps manage the Mirador3 "monorepo" + +### using lerna + +#### `$ lerna bootstrap` + +Link local packages together and installs package dependencies + +#### `$ lerna run build` + +build production packages + +#### `$ lerna run start` + +start the development mode application + +#### `$ lerna run test` + +lints and runs tests (use with --stream to see output) + +#### `$ lerna run test:coverage` + +runs test with coverage diff --git a/packages/mirador3-app/.eslintignore b/packages/mirador3-app/.eslintignore new file mode 100644 index 0000000..594cc78 --- /dev/null +++ b/packages/mirador3-app/.eslintignore @@ -0,0 +1,4 @@ +build/ +config/ +scripts/ +coverage/ diff --git a/packages/mirador3-app/README.md b/packages/mirador3-app/README.md index 897dc83..385f6f7 100644 --- a/packages/mirador3-app/README.md +++ b/packages/mirador3-app/README.md @@ -27,16 +27,6 @@ Your app is ready to be deployed! See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** - -If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. - -You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. - ## Learn More You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). diff --git a/packages/mirador3-app/jest.json b/packages/mirador3-app/jest.json new file mode 100644 index 0000000..1ee4de1 --- /dev/null +++ b/packages/mirador3-app/jest.json @@ -0,0 +1,44 @@ +{ + "collectCoverageFrom": [ + "src/**/*.{js,jsx,ts,tsx}", + "!src/**/*.d.ts" + ], + "coverageDirectory": "/coverage", + "coverageReporters": ["html"], + "resolver": "jest-pnp-resolver", + "setupFiles": [ + "jest-canvas-mock" + ], + "setupTestFrameworkScriptFile": "/src/setupTests.js", + "testMatch": [ + "/src/**/__tests__/**/*.{js,jsx,ts,tsx}", + "/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}" + ], + "testEnvironment": "jsdom", + "testURL": "http://localhost", + "transform": { + "^.+\\.(js|jsx|ts|tsx)$": "/node_modules/babel-jest", + "^.+\\.css$": "/config/jest/cssTransform.js", + "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "/config/jest/fileTransform.js" + }, + "transformIgnorePatterns": [ + "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$", + "^.+\\.module\\.(css|sass|scss)$" + ], + "moduleNameMapper": { + "^react-native$": "react-native-web", + "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy" + }, + "moduleFileExtensions": [ + "web.js", + "js", + "web.ts", + "ts", + "web.tsx", + "tsx", + "json", + "web.jsx", + "jsx", + "node" + ] +} diff --git a/packages/mirador3-app/package.json b/packages/mirador3-app/package.json index c7b4f4a..8f62071 100644 --- a/packages/mirador3-app/package.json +++ b/packages/mirador3-app/package.json @@ -70,9 +70,12 @@ "workbox-webpack-plugin": "3.6.3" }, "scripts": { + "lint": "node_modules/.bin/eslint ./", "start": "node scripts/start.js", "build": "node scripts/build.js", - "test": "node scripts/test.js" + "test": "npm run lint && jest -c jest.json", + "test:watch": "jest -c jest.json --watch", + "test:coverage": "jest -c jest.json --coverage" }, "eslintConfig": { "extends": "react-app" @@ -83,49 +86,7 @@ "not ie <= 11", "not op_mini all" ], - "jest": { - "collectCoverageFrom": [ - "src/**/*.{js,jsx,ts,tsx}", - "!src/**/*.d.ts" - ], - "resolver": "jest-pnp-resolver", - "setupFiles": [ - "jest-canvas-mock" - ], - "setupTestFrameworkScriptFile": "/src/setupTests.js", - "testMatch": [ - "/src/**/__tests__/**/*.{js,jsx,ts,tsx}", - "/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}" - ], - "testEnvironment": "jsdom", - "testURL": "http://localhost", - "transform": { - "^.+\\.(js|jsx|ts|tsx)$": "/node_modules/babel-jest", - "^.+\\.css$": "/config/jest/cssTransform.js", - "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "/config/jest/fileTransform.js" - }, - "transformIgnorePatterns": [ - "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$", - "^.+\\.module\\.(css|sass|scss)$" - ], - "moduleNameMapper": { - "^react-native$": "react-native-web", - "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy" - }, - "moduleFileExtensions": [ - "web.js", - "js", - "web.ts", - "ts", - "web.tsx", - "tsx", - "json", - "web.jsx", - "jsx", - "node" - ] - }, - "babel": { + "babel": { "presets": [ "react-app" ] diff --git a/packages/mirador3-app/scripts/test.js b/packages/mirador3-app/scripts/test.js deleted file mode 100644 index 3d51ca5..0000000 --- a/packages/mirador3-app/scripts/test.js +++ /dev/null @@ -1,52 +0,0 @@ -// Do this as the first thing so that any code reading it knows the right env. -process.env.BABEL_ENV = 'test'; -process.env.NODE_ENV = 'test'; -process.env.PUBLIC_URL = ''; - -// Makes the script crash on unhandled rejections instead of silently -// ignoring them. In the future, promise rejections that are not handled will -// terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', (err) => { - throw err; -}); - -// Ensure environment variables are read. -require('../config/env'); - - -const jest = require('jest'); -const execSync = require('child_process').execSync; - -let argv = process.argv.slice(2); - -function isInGitRepository() { - try { - execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' }); - return true; - } catch (e) { - return false; - } -} - -function isInMercurialRepository() { - try { - execSync('hg --cwd . root', { stdio: 'ignore' }); - return true; - } catch (e) { - return false; - } -} - -// Watch unless on CI, in coverage mode, or explicitly running all tests -if ( - !process.env.CI && - argv.indexOf('--coverage') === -1 && - argv.indexOf('--watchAll') === -1 -) { - // https://github.com/facebook/create-react-app/issues/5210 - const hasSourceControl = isInGitRepository() || isInMercurialRepository(); - argv.push(hasSourceControl ? '--watch' : '--watchAll'); -} - - -jest.run(argv); diff --git a/packages/mirador3-core/.babelrc b/packages/mirador3-core/.babelrc deleted file mode 100644 index a29ac99..0000000 --- a/packages/mirador3-core/.babelrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "presets": [ - "@babel/preset-env" - ] -} diff --git a/packages/mirador3-core/.eslintignore b/packages/mirador3-core/.eslintignore index bf55ac2..5dd89f0 100644 --- a/packages/mirador3-core/.eslintignore +++ b/packages/mirador3-core/.eslintignore @@ -1,2 +1,3 @@ lib/ config/ +coverage/ diff --git a/packages/mirador3-core/jest.json b/packages/mirador3-core/jest.json new file mode 100644 index 0000000..dfab5cd --- /dev/null +++ b/packages/mirador3-core/jest.json @@ -0,0 +1,42 @@ +{ + "automock": false, + "setupTestFrameworkScriptFile": "/src/setupTests.js", + "collectCoverageFrom": [ + "src/**/*.{js,jsx,ts,tsx}", + "!src/**/*.d.ts" + ], + "coverageDirectory": "/coverage", + "coverageReporters": ["html"], + "resolver": "jest-pnp-resolver", + "testMatch": [ + "/src/**/__tests__/**/*.{js,jsx,ts,tsx}", + "/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}" + ], + "testEnvironment": "jsdom", + "testURL": "http://localhost", + "transform": { + "^.+\\.(js|jsx|ts|tsx)$": "/node_modules/babel-jest", + "^.+\\.css$": "/config/jest/cssTransform.js", + "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "/config/jest/fileTransform.js" + }, + "transformIgnorePatterns": [ + "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$", + "^.+\\.module\\.(css|sass|scss)$" + ], + "moduleNameMapper": { + "^react-native$": "react-native-web", + "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy" + }, + "moduleFileExtensions": [ + "web.js", + "js", + "web.ts", + "ts", + "web.tsx", + "tsx", + "json", + "web.jsx", + "jsx", + "node" + ] +} diff --git a/packages/mirador3-core/package.json b/packages/mirador3-core/package.json index d99042a..450d013 100644 --- a/packages/mirador3-core/package.json +++ b/packages/mirador3-core/package.json @@ -7,8 +7,9 @@ "repository": "https://github.com/ProjectMirador/research-and-demos/mirador3-core", "scripts": { "lint": "node_modules/.bin/eslint ./", - "test": "npm run build && npm run lint && node_modules/.bin/jest", - "test:watch": "npm test -- --watch", + "test": "npm run lint && jest -c jest.json", + "test:watch": "jest -c jest.json --watch", + "test:coverage": "jest -c jest.json --coverage", "build": "node_modules/.bin/webpack", "build:watch": "node_modules/.bin/webpack --watch" }, @@ -45,44 +46,9 @@ "webpack": "^4.24.0", "webpack-cli": "^3.1.2" }, - "jest": { - "automock": false, - "setupTestFrameworkScriptFile": "/src/setupTests.js", - "collectCoverageFrom": [ - "src/**/*.{js,jsx,ts,tsx}", - "!src/**/*.d.ts" - ], - "resolver": "jest-pnp-resolver", - "testMatch": [ - "/src/**/__tests__/**/*.{js,jsx,ts,tsx}", - "/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}" - ], - "testEnvironment": "jsdom", - "testURL": "http://localhost", - "transform": { - "^.+\\.(js|jsx|ts|tsx)$": "/node_modules/babel-jest", - "^.+\\.css$": "/config/jest/cssTransform.js", - "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "/config/jest/fileTransform.js" - }, - "transformIgnorePatterns": [ - "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$", - "^.+\\.module\\.(css|sass|scss)$" - ], - "moduleNameMapper": { - "^react-native$": "react-native-web", - "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy" - }, - "moduleFileExtensions": [ - "web.js", - "js", - "web.ts", - "ts", - "web.tsx", - "tsx", - "json", - "web.jsx", - "jsx", - "node" + "babel": { + "presets": [ + "@babel/preset-env" ] } }