Skip to content

Commit

Permalink
[Tests] use semver to determine adapter version
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 17, 2019
1 parent 558d5cf commit 6730c5b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ matrix:
- node_js: "lts/*"
env: LINT=true
- node_js: "lts/*"
env: REACT=16.7 ADAPTER=16
env: REACT=16.7
- node_js: "lts/*"
env: REACT=16.6 ADAPTER=16
env: REACT=16.6
- node_js: "lts/*"
env: REACT=16.5 ADAPTER=16
env: REACT=16.5
- node_js: "lts/*"
env: REACT=16.4 ADAPTER=16
env: REACT=16.4
- node_js: "lts/*"
env: REACT=16.3 ADAPTER=16
- node_js: "6"
Expand Down
43 changes: 29 additions & 14 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('path');
const fs = require('fs');
const spawn = require('child_process').spawn;
const rimraf = require('rimraf');
const semver = require('semver');

const promisify = fn => new Promise((res, rej) => {
const done = (err, val) => (err ? rej(err) : res(val));
Expand Down Expand Up @@ -41,21 +42,35 @@ const version = process.argv[2];

const root = process.cwd();

const adapterVersions = {
'15.0': 15.4,
15.1: 15.4,
15.2: 15.4,
15.3: 15.4,
15.5: 15,
'16.0': 16.1,
16.4: 16,
16.5: 16,
16.6: 16,
16.7: 16,
16.8: 16,
};
function getAdapter(reactVersion) {
if (semver.intersects(reactVersion, '0.13.x')) {
return '13';
}
if (semver.intersects(reactVersion, '0.14.x')) {
return '14';
}
if (semver.intersects(reactVersion, '^15.0.0-0')) {
if (semver.intersects(reactVersion, '< 15.5')) {
return '15.4';
}
return '15';
}
if (semver.intersects(reactVersion, '^16.0.0-0')) {
if (semver.intersects(reactVersion, '~16.0 || ~16.1')) {
return '16.1';
}
if (semver.intersects(reactVersion, '~16.2')) {
return '16.2';
}
if (semver.intersects(reactVersion, '~16.3')) {
return '16.3';
}
return '16';
}
return null;
}
const reactVersion = version < 15 ? '0.' + version : version;
const adapterVersion = process.env.ADAPTER || adapterVersions[version] || version;
const adapterVersion = process.env.ADAPTER || getAdapter(reactVersion) || version;
const adapterName = `enzyme-adapter-react-${adapterVersion}`;
const adapterPackageJsonPath = path.join(root, 'packages', adapterName, 'package.json');
const testPackageJsonPath = path.join(root, 'packages', 'enzyme-test-suite', 'package.json');
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"prop-types": "^15.7.2",
"rimraf": "^2.6.3",
"safe-publish-latest": "^1.1.2",
"semver": "^5.6.0",
"webpack": "^1.15.0"
},
"dependencies": {}
Expand Down

0 comments on commit 6730c5b

Please sign in to comment.