Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Jest config #6654

Merged
merged 36 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b0d7888
Remove babel-core dependency
ianschmitz Mar 15, 2019
637d3cf
Update babel-plugin-tester to remove babel-core dependency
ianschmitz Mar 15, 2019
4db20cb
Clean up jest config
ianschmitz Mar 16, 2019
98b5391
Try updating kitchensink initDOM to use latest jsdom
ianschmitz Mar 16, 2019
2875b1d
Update jsdom logic in tests
ianschmitz Mar 16, 2019
d36d8e3
Use new when constructing JSDOM document
ianschmitz Mar 16, 2019
3975201
WIP
ianschmitz Mar 16, 2019
0bb3e3e
WIP
ianschmitz Mar 17, 2019
c6896b1
WIP
ianschmitz Apr 2, 2019
7f10703
Merge remote-tracking branch 'upstream/master' into jest-cleanup
ianschmitz Apr 3, 2019
13b8af9
Synchronize Jest versions to fix build error
ianschmitz Apr 3, 2019
2ae7780
Remove unnecessary testURL option
ianschmitz Apr 3, 2019
d7e2f5d
Fix package version conflicts
ianschmitz Apr 3, 2019
d945daa
Handle when kitchensink test fails to load
ianschmitz Apr 3, 2019
8d4149d
Port other test suites
ianschmitz Apr 3, 2019
326f7d2
Bump to Jest 24.7.0
ianschmitz Apr 3, 2019
1449860
Missed a jest reference
ianschmitz Apr 3, 2019
a647d31
Fix BuildEmitter propTypes
ianschmitz Apr 4, 2019
ef782a8
Can't run this locally.. go travis
ianschmitz Apr 4, 2019
6b372dd
Bump Jest to 24.7.1
ianschmitz Apr 4, 2019
48f82f4
More debugging
ianschmitz Apr 4, 2019
1a801b9
Debuggg
ianschmitz Apr 4, 2019
d0392c8
Better logging
ianschmitz Apr 4, 2019
c29234b
Work around hash issue
ianschmitz Apr 4, 2019
f633650
Fix reference error
ianschmitz Apr 4, 2019
834aecd
More fixes
ianschmitz Apr 4, 2019
4f08b55
It's getting late...
ianschmitz Apr 4, 2019
604f8bc
I wish i could run this locally
ianschmitz Apr 4, 2019
f054eaa
url wasn't a URL
ianschmitz Apr 4, 2019
e7575af
Try to fix eject issues
ianschmitz Apr 4, 2019
bac450a
More eject stuff
ianschmitz Apr 4, 2019
009b5d1
Fix Jest watch plugins on eject
ianschmitz Apr 4, 2019
2abbf5a
Unpin babel-jest in react-error-overlay
ianschmitz Apr 4, 2019
65fdd4f
Unpin babel-jest in react-scripts
ianschmitz Apr 4, 2019
715659d
Pin babel-jest in react-error-overlay
iansu Apr 4, 2019
5988359
Pin babel-jest in react-scripts
iansu Apr 4, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"get-port": "^4.2.0",
"globby": "^9.1.0",
"husky": "^1.3.1",
"jest": "^24.5.0",
"jest": "24.7.1",
"lerna": "2.9.1",
"lerna-changelog": "~0.8.2",
"lint-staged": "^8.0.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-named-asset-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"@babel/core": "^7.1.0"
},
"devDependencies": {
"babel-plugin-tester": "^5.5.1",
"jest": "^24.5.0"
"babel-plugin-tester": "^6.0.1",
"jest": "24.7.1"
},
"scripts": {
"test": "jest"
Expand Down
2 changes: 1 addition & 1 deletion packages/confusing-browser-globals/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"index.js"
],
"devDependencies": {
"jest": "24.5.0"
"jest": "24.7.1"
}
}
2 changes: 1 addition & 1 deletion packages/react-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
"devDependencies": {
"cross-env": "^5.2.0",
"jest": "^24.5.0"
"jest": "24.7.1"
},
"scripts": {
"test": "cross-env FORCE_COLOR=true jest"
Expand Down
5 changes: 2 additions & 3 deletions packages/react-error-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
"@babel/code-frame": "7.0.0",
"@babel/core": "7.3.4",
"anser": "1.4.8",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.1",
"babel-jest": "24.5.0",
"babel-jest": "24.7.1",
"babel-loader": "8.0.5",
"babel-preset-react-app": "^7.0.2",
"chalk": "^2.4.2",
Expand All @@ -49,7 +48,7 @@
"eslint-plugin-react": "7.12.4",
"flow-bin": "^0.63.1",
"html-entities": "1.2.1",
"jest": "24.5.0",
"jest": "24.7.1",
"jest-fetch-mock": "2.1.1",
"object-assign": "4.1.1",
"promise": "8.0.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"bootstrap": "4.1.1",
"jest": "24.5.0",
"jest": "24.7.1",
"node-sass": "4.8.3",
"normalize.css": "7.0.0",
"prop-types": "15.5.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-scripts/fixtures/kitchensink/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Tests are automatically run by the CI tools.
In order to run them locally, without having to manually install and configure everything, the `yarn e2e:docker` CLI command can be used.

This is a simple script that runs a **Docker** container, where the node version, git branch to clone, test suite, and whether to run it with `yarn` or `npm` can be chosen.
Simply run `yarn e2e:docker -- --help` to get additional info.
Simply run `yarn e2e:docker --help` to get additional info.

If you need guidance installing **Docker**, you should follow their [official docs](https://docs.docker.com/engine/installation/).

Expand Down
22 changes: 12 additions & 10 deletions packages/react-scripts/fixtures/kitchensink/integration/env.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ import initDOM from './initDOM';

describe('Integration', () => {
describe('Environment variables', () => {
let doc;

afterEach(() => {
doc && doc.defaultView.close();
doc = undefined;
});

it('file env variables', async () => {
const doc = await initDOM('file-env-variables');
doc = await initDOM('file-env-variables');

expect(
doc.getElementById('feature-file-env-original-1').textContent
Expand All @@ -34,18 +41,16 @@ describe('Integration', () => {
'x-from-development-env'
);
}
doc.defaultView.close();
});

it('NODE_PATH', async () => {
const doc = await initDOM('node-path');
doc = await initDOM('node-path');

expect(doc.getElementById('feature-node-path').childElementCount).toBe(4);
doc.defaultView.close();
});

it('PUBLIC_URL', async () => {
const doc = await initDOM('public-url');
doc = await initDOM('public-url');

const prefix =
process.env.NODE_ENV === 'development'
Expand All @@ -57,20 +62,18 @@ describe('Integration', () => {
expect(
doc.querySelector('head link[rel="shortcut icon"]').getAttribute('href')
).toBe(`${prefix}/favicon.ico`);
doc.defaultView.close();
});

it('shell env variables', async () => {
const doc = await initDOM('shell-env-variables');
doc = await initDOM('shell-env-variables');

expect(
doc.getElementById('feature-shell-env-variables').textContent
).toBe('fromtheshell.');
doc.defaultView.close();
});

it('expand .env variables', async () => {
const doc = await initDOM('expand-env-variables');
doc = await initDOM('expand-env-variables');

expect(doc.getElementById('feature-expand-env-1').textContent).toBe(
'basic'
Expand All @@ -84,7 +87,6 @@ describe('Integration', () => {
expect(
doc.getElementById('feature-expand-env-existing').textContent
).toBe('fromtheshell');
doc.defaultView.close();
});
});
});
105 changes: 59 additions & 46 deletions packages/react-scripts/fixtures/kitchensink/integration/initDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,31 @@
*/

const fs = require('fs');
const http = require('http');
const jsdom = require('jsdom/lib/old-api.js');
const { JSDOM, ResourceLoader } = require('jsdom');
const path = require('path');
const url = require('url');

let getMarkup;
export let resourceLoader;

if (process.env.E2E_FILE) {
const file = path.isAbsolute(process.env.E2E_FILE)
const file =
process.env.E2E_FILE &&
(path.isAbsolute(process.env.E2E_FILE)
? process.env.E2E_FILE
: path.join(process.cwd(), process.env.E2E_FILE);

const markup = fs.readFileSync(file, 'utf8');
getMarkup = () => markup;
: path.join(process.cwd(), process.env.E2E_FILE));

export const fetchFile = url => {
const pathPrefix = process.env.PUBLIC_URL.replace(/^https?:\/\/[^/]+\/?/, '');
return fs.readFileSync(
path.join(path.dirname(file), url.pathname.replace(pathPrefix, '')),
'utf8'
);
};

resourceLoader = (resource, callback) =>
callback(
null,
fs.readFileSync(
path.join(
path.dirname(file),
resource.url.pathname.replace(pathPrefix, '')
),
'utf8'
)
);
} else if (process.env.E2E_URL) {
getMarkup = () =>
new Promise(resolve => {
http.get(process.env.E2E_URL, res => {
let rawData = '';
res.on('data', chunk => (rawData += chunk));
res.on('end', () => resolve(rawData));
});
});
const fileResourceLoader = new class FileResourceLoader extends ResourceLoader {
fetch(href, options) {
return Promise.resolve(fetchFile(url.parse(href)));
}
}();

resourceLoader = (resource, callback) => resource.defaultFetch(callback);
} else {
if (!process.env.E2E_FILE && !process.env.E2E_URL) {
it.only('can run jsdom (at least one of "E2E_FILE" or "E2E_URL" environment variables must be provided)', () => {
expect(
new Error("This isn't the error you are looking for.")
Expand All @@ -54,18 +39,46 @@ if (process.env.E2E_FILE) {
}

export default feature =>
new Promise(async resolve => {
const markup = await getMarkup();
const host = process.env.E2E_URL || 'http://www.example.org/spa:3000';
const doc = jsdom.jsdom(markup, {
created: (_, win) =>
win.addEventListener('ReactFeatureDidMount', () => resolve(doc), true),
deferClose: true,
pretendToBeVisual: true,
resourceLoader,
url: `${host}#${feature}`,
virtualConsole: jsdom.createVirtualConsole().sendTo(console),
});
new Promise(async (resolve, reject) => {
try {
const host = process.env.E2E_URL || 'http://www.example.org/spa:3000';
const url = `${host}#${feature}`;

let window;

if (process.env.E2E_FILE) {
window = (await JSDOM.fromFile(file, {
pretendToBeVisual: true,
resources: fileResourceLoader,
runScripts: 'dangerously',
url,
})).window;
} else {
window = (await JSDOM.fromURL(url, {
pretendToBeVisual: true,
resources: 'usable',
runScripts: 'dangerously',
})).window;
}

const { document } = window;

document.addEventListener(
'ReactFeatureDidMount',
() => resolve(document),
{ capture: true, once: true }
);
document.addEventListener(
'ReactFeatureError',
() => {
// Cleanup jsdom instance since we don't need it anymore
window.close();

doc.close();
reject(`Error loading feature: ${feature}`);
},
{ capture: true, once: true }
);
} catch (e) {
reject(e);
}
});
Loading