Skip to content

Commit

Permalink
Lerna init, move src/* and test/* into enzyme
Browse files Browse the repository at this point in the history
  • Loading branch information
lelandrichardson committed Aug 20, 2017
1 parent e7ec246 commit 860341b
Show file tree
Hide file tree
Showing 85 changed files with 786 additions and 129 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
_book/
build/
node_modules/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ _book

# Only apps should have lockfiles
package-lock.json

packages/*/build/
28 changes: 4 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ node_js:
- "8"
- "6"
- "4"
- "0.12"
- "0.10"
before_install:
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then npm install -g npm@1.3 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 2.*) npm install -g npm@2 ;; esac ; fi'
- 'if [ "${TRAVIS_NODE_VERSION%${TRAVIS_NODE_VERSION#[0-9]}}" = "0" ] || [ "${TRAVIS_NODE_VERSION:0:4}" = "iojs" ]; then npm install -g npm@4.5 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi'
install:
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then nvm install 0.8 && npm install -g npm@1.3 && npm install -g npm@1.4.28 && npm install -g npm@2 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
before_script:
- 'rm ./node_modules/.bin/npm 2>/dev/null || :'
- "./node_modules/.bin/lerna bootstrap"
- "./node_modules/.bin/lerna run build"
- "sh install-relevant-react.sh"
- if [ -n "${KARMA-}" ]; then export CHROME_BIN=chromium-browser; export DISPLAY=:99.0; sh -e /etc/init.d/xvfb start; fi
script:
- 'if [ -n "${EXAMPLE-}" ]; then npm run test:env -- "${EXAMPLE}" ; elif [ -n "${LINT-}" ]; then npm run lint; elif [ -n "${KARMA-}" ]; then npm run test:karma -- --single-run; elif [ -n "${REACT-}" ]; then npm run travis; else false ; fi'
- 'if [ -n "${LINT-}" ]; then npm run lint; elif [ -n "${KARMA-}" ]; then npm run test:karma -- --single-run; elif [ -n "${REACT-}" ]; then npm run travis; else false ; fi'
after_script:
- 'if [ "${TRAVIS_NODE_VERSION}" = "4" ] || [ "${TRAVIS_NODE_VERSION}" = "0.12" ]; then cat ./coverage/lcov.info | ./node_modules/.bin/coveralls ; fi'
sudo: false
Expand All @@ -23,16 +21,6 @@ matrix:
include:
- node_js: "6"
env: LINT=true
- node_js: "6"
env: EXAMPLE=mocha
- node_js: "6"
env: EXAMPLE=karma
- node_js: "6"
env: EXAMPLE=react-native
- node_js: "6"
env: EXAMPLE=karma-webpack
- node_js: "6"
env: EXAMPLE=jest
- node_js: "6"
env: KARMA=true REACT=0.13
- node_js: "6"
Expand All @@ -44,14 +32,6 @@ matrix:
- node_js: "6"
env: KARMA=true REACT=16
allow_failures:
- node_js: "6"
env: EXAMPLE=react-native
- node_js: "6"
env: EXAMPLE=mocha
- node_js: "6"
env: EXAMPLE=karma
- node_js: "6"
env: EXAMPLE=karma-webpack
- node_js: "6"
env: KARMA=true REACT=16
env:
Expand Down
96 changes: 96 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const path = require('path');
const fs = require('fs');
const child_process = require('child_process');
const rimraf = require('rimraf');

const promisify = fn => new Promise((res, rej) => {
const done = (err, val) => (err ? rej(err) : res(val));
fn(done);
});
const getJSON = fpath => getFile(fpath).then(json => JSON.parse(json));
const getFile = fpath => promisify(cb => fs.readFile(fpath, 'utf8', cb));
const getFiles = fpath => promisify(cb => fs.readdir(fpath, cb));
const writeFile = (fpath, src) => promisify(cb => fs.writeFile(fpath, src, cb));
const writeJSON = (fpath, json, pretty = false) => writeFile(
fpath,
pretty
? JSON.stringify(json, null, 2)
: JSON.stringify(json)
);
const primraf = path => promisify(cb => rimraf(path, cb));
const run = cmd => promisify(cb => child_process.exec(cmd, cb));

// This script is executed with a single argument, indicating the version of
// react and adapters etc. that we want to set ourselves up for testing.
// should be "14" for "enzyme-adapter-react-14", "15.4" for "enzyme-adapter-react-15.4", etc.
const version = process.argv[2];

// This script will do the following:
//
// 1. remove / uninstall all relevant modules
// 2. find the adapter for the passed in version
// 3. get the package.json for the adapter
// 4. add the adapter to the dev-deps for enzyme-test-suite package
// 5. call lerna bootstrap to link all the packages
// 6. install all of the package's peer deps at the top level

var root = process.cwd();
var adapterName = 'enzyme-adapter-react-' + version;
var adapterPackageJsonPath = path.join(root, 'packages', adapterName, 'package.json');
var testPackageJsonPath = path.join(root, 'packages', 'enzyme-test-suite', 'package.json');

if (!fs.statSync(adapterPackageJsonPath)) {
throw new Error('Adapter not found: "' + adapterName + '"');
}

const packagesToRemove = [
'react',
'react-dom',
'react-addons-test-utils',
'react-test-renderer',
'create-react-class',
].map(s => `./node_modules/${s}`);

const additionalDirsToRemove = [
'node_modules/.bin/npm',
'node_modules/.bin/npm.cmd',
];

const rmrfArgs = []
.concat(packagesToRemove)
.concat(additionalDirsToRemove)
.join(' ');

Promise.resolve()
.then(() => primraf(rmrfArgs))
.then(() => run('npm i'))
.then(() => Promise.all([
getJSON(adapterPackageJsonPath),
getJSON(testPackageJsonPath),
]))
.then(([adapterJson, testJson]) => {
const peerDeps = adapterJson.peerDependencies;
const installs = Object.keys(peerDeps)
.filter(key => !key.startsWith('enzyme'))
.map(key => `${key}@'${peerDeps[key]}'`)
.join(' ');

testJson.dependencies[adapterName] = adapterJson.version;

return Promise.all([
// npm install the peer deps at the root
run(`npm i --no-save ${installs}`),

// add the adapter to the dependencies of the test suite
writeJSON(testPackageJsonPath, testJson, true),
]);
})
.then(() => run('lerna bootstrap'))
.then(() => getJSON(testPackageJsonPath))
.then(testJson => {
// now that we've lerna bootstrapped, we can remove the adapter from the
// package.json so there is no diff
delete testJson.dependencies[adapterName];
return writeJSON(testPackageJsonPath, testJson, true);
})
.catch(err => console.error(err));
10 changes: 0 additions & 10 deletions example-test.sh

This file was deleted.

18 changes: 9 additions & 9 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
require('babel-register');

var IgnorePlugin = require('webpack').IgnorePlugin;
var is = require('./test/_helpers/version').is;
var is = require('./packages/enzyme-test-suite/test/_helpers/version').is;

function getPlugins() {
const adapter13 = new IgnorePlugin(/adapters\/ReactThirteenAdapter/);
const adapter14 = new IgnorePlugin(/adapters\/ReactFourteenAdapter/);
const adapter154 = new IgnorePlugin(/adapters\/ReactFifteenFourAdapter/);
const adapter15 = new IgnorePlugin(/adapters\/ReactFifteenFiveAdapter/);
const adapter16 = new IgnorePlugin(/adapters\/ReactSixteenAdapter/);
const adapter13 = new IgnorePlugin(/enzyme-adapter-react-13$/);
const adapter14 = new IgnorePlugin(/enzyme-adapter-react-14$/);
const adapter154 = new IgnorePlugin(/enzyme-adapter-react-15\.4$/);
const adapter15 = new IgnorePlugin(/enzyme-adapter-react-15$/);
const adapter16 = new IgnorePlugin(/enzyme-adapter-react-16$/);

var plugins = [
adapter13,
Expand Down Expand Up @@ -66,11 +66,11 @@ module.exports = function karma(config) {
reporters: ['dots'],

files: [
'test/*.{jsx,js}',
'packages/enzyme-test-suite/test/*.{jsx,js}',
],

exclude: [
'test/_helpers/index.jsx',
'packages/enzyme-test-suite/test/_helpers/index.jsx',
],

browsers: [
Expand All @@ -79,7 +79,7 @@ module.exports = function karma(config) {
],

preprocessors: {
'test/*.{jsx,js}': ['webpack', 'sourcemap'],
'packages/enzyme-test-suite/test/*.{jsx,js}': ['webpack', 'sourcemap'],
},

webpack: {
Expand Down
7 changes: 7 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"lerna": "2.0.0",
"packages": [
"packages/*"
],
"version": "2.9.1"
}
67 changes: 23 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{
"name": "enzyme",
"version": "2.9.1",
"private": true,
"version": "0.0.1",
"description": "JavaScript Testing utilities for React",
"homepage": "http://airbnb.io/enzyme/",
"main": "build",
"scripts": {
"prepublish": "not-in-publish || (npm run clean && npm run build && safe-publish-latest)",
"preversion": "npm run clean && npm run check",
"postversion": "git push && git push --tags && npm run clean && npm run docs:publish",
"version": "npm run build",
"clean": "rimraf build",
"lint": "eslint --ext js,jsx src test",
"version": "lerna run build",
"clean": "lerna run clean",
"lint": "lerna run lint",
"postlint": "npm run docs:lint",
"check": "npm run lint && npm run test:all",
"build": "babel src --out-dir build",
"pretest": "npm run lint",
"check": "lerna run lint && npm run test:all",
"build": "lerna run build",
"build:watch": "lerna run build",
"pretest": "lerna run lint",
"test": "npm run clean && npm run build && npm run test:only",
"test:only": "mocha --recursive test",
"test:only": "mocha --recursive packages/enzyme-test-suite/test",
"test:single": "mocha --watch",
"test:watch": "mocha --recursive --watch test",
"test:karma": "karma start",
"test:watch": "mocha --recursive --watch packages/enzyme-test-suite/test",
"test:karma": "npm run build && karma start",
"test:env": "sh ./example-test.sh",
"test:all": "npm run react:13 && npm run test:only && npm run react:14 && npm run test:only && npm run react:15.4 && npm run test:only && npm run react:15 && npm run test:only && npm run react:16 && npm run test:only",
"clean-local-npm": "rimraf node_modules/.bin/npm node_modules/.bin/npm.cmd",
"react:clean": "npm run clean-local-npm && rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils node_modules/react-test-renderer node_modules/create-react-class && npm prune",
"react:13": "npm run react:clean && npm install && npm i --no-save react@0.13",
"react:14": "npm run react:clean && npm install && npm i --no-save react@0.14 react-dom@0.14 react-addons-test-utils@0.14",
"react:15.4": "npm run react:clean && npm install && npm i --no-save react@15.4 react-dom@15.4 react-addons-test-utils@15.4",
"react:15": "npm run react:clean && npm install && npm i --no-save react@15 react-dom@15 create-react-class@15 react-test-renderer@^15.5.4",
"react:16": "npm run react:clean && npm install && npm i --no-save react@^16.0.0-0 react-dom@^16.0.0-0 create-react-class@^15.6.0 react-test-renderer@^16.0.0-0",
"react:13": "npm run env -- 13",
"react:14": "npm run env -- 14",
"react:15.4": "npm run env -- 15.4",
"react:15": "npm run env -- 15",
"react:16": "npm run env -- 16",
"env": "babel-node ./env.js",
"docs:clean": "rimraf _book",
"docs:lint": "eslint --ext md --config .eslintrc-markdown .",
"docs:lint": "eslint --ext md --config .eslintrc-markdown --ignore-path .eslintignore .",
"docs:prepare": "gitbook install",
"docs:build": "npm run docs:prepare && gitbook build",
"docs:watch": "npm run docs:prepare && gitbook serve",
"docs:publish": "npm run docs:clean && npm run docs:build && cd _book && git init && git commit --allow-empty -m 'update book' && git fetch git@github.com:airbnb/enzyme.git gh-pages && git checkout -b gh-pages && git add . && git commit -am 'update book' && git push git@github.com:airbnb/enzyme.git gh-pages --force",
"travis": "babel-node \"$(which istanbul)\" cover --report html _mocha -- test --recursive"
"travis": "npm run build && babel-node \"$(which istanbul)\" cover --report html _mocha -- packages/enzyme-test-suite/test --recursive"
},
"repository": {
"type": "git",
Expand All @@ -57,21 +57,8 @@
],
"author": "Leland Richardson <leland.richardson@airbnb.com>",
"license": "MIT",
"dependencies": {
"cheerio": "^0.22.0",
"function.prototype.name": "^1.0.3",
"is-subset": "^0.1.1",
"lodash": "^4.17.4",
"object-is": "^1.0.1",
"object.assign": "^4.0.4",
"object.entries": "^1.0.4",
"object.values": "^1.0.4",
"prop-types": "^15.5.10",
"raf": "^3.3.2",
"semver": "^5.4.1",
"uuid": "^3.1.0"
},
"devDependencies": {
"prop-types": "^15.5.10",
"babel-cli": "^6.24.1",
"babel-core": "^6.25.0",
"babel-eslint": "^7.2.3",
Expand All @@ -82,11 +69,6 @@
"chai": "^4.1.1",
"coveralls": "^2.13.1",
"create-react-class": "^15.6.0",
"enzyme-example-jest": "^0.1.0",
"enzyme-example-karma": "^0.1.1",
"enzyme-example-karma-webpack": "^0.1.4",
"enzyme-example-mocha": "^0.1.0",
"enzyme-example-react-native": "^0.1.0",
"eslint": "^4.4.1",
"eslint-config-airbnb": "^15.1.0",
"eslint-plugin-import": "^2.7.0",
Expand All @@ -104,14 +86,11 @@
"karma-mocha": "^1.3.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.1",
"lerna": "^2.0.0",
"mocha": "^3.5.0",
"rimraf": "^2.6.1",
"safe-publish-latest": "^1.1.1",
"sinon": "^2.4.1",
"webpack": "^1.13.3",
"react": "0.13.x || 0.14.x || ^15.0.0-0 || ^16.0.0-0"
},
"peerDependencies": {
"react": "0.13.x || 0.14.x || ^15.0.0-0 || ^16.0.0-0"
"webpack": "^1.13.3"
}
}
6 changes: 6 additions & 0 deletions packages/enzyme-adapter-react-13/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": ["airbnb"],
"plugins": [
["transform-replace-object-assign", "object.assign"],
],
}
2 changes: 2 additions & 0 deletions packages/enzyme-adapter-react-13/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_book/
build/
13 changes: 13 additions & 0 deletions packages/enzyme-adapter-react-13/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rules": {
"react/no-find-dom-node": 0,
"react/no-multi-comp": 0,
"no-underscore-dangle": 0,
"class-methods-use-this": 0
},
"settings": {
"react": {
"version": "0.13.0"
}
}
}
Loading

0 comments on commit 860341b

Please sign in to comment.