Skip to content

Converting mocha tests to jest #2316

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 14 additions & 17 deletions packages/react-scripts/fixtures/kitchensink/integration/env.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

import { expect } from 'chai';
import initDOM from './initDOM';

describe('Integration', () => {
Expand All @@ -15,23 +14,23 @@ describe('Integration', () => {

expect(
doc.getElementById('feature-file-env-original-1').textContent
).to.equal('from-original-env-1');
).toBe('from-original-env-1');
expect(
doc.getElementById('feature-file-env-original-2').textContent
).to.equal('override-from-original-local-env-2');
).toBe('override-from-original-local-env-2');

if (process.env.NODE_ENV === 'production') {
expect(doc.getElementById('feature-file-env').textContent).to.equal(
expect(doc.getElementById('feature-file-env').textContent).toBe(
'production'
);
expect(doc.getElementById('feature-file-env-x').textContent).to.equal(
expect(doc.getElementById('feature-file-env-x').textContent).toBe(
'x-from-production-env'
);
} else {
expect(doc.getElementById('feature-file-env').textContent).to.equal(
expect(doc.getElementById('feature-file-env').textContent).toBe(
'development'
);
expect(doc.getElementById('feature-file-env-x').textContent).to.equal(
expect(doc.getElementById('feature-file-env-x').textContent).toBe(
'x-from-development-env'
);
}
Expand All @@ -40,9 +39,7 @@ describe('Integration', () => {
it('NODE_PATH', async () => {
const doc = await initDOM('node-path');

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

it('PUBLIC_URL', async () => {
Expand All @@ -52,37 +49,37 @@ describe('Integration', () => {
process.env.NODE_ENV === 'development'
? ''
: 'http://www.example.org/spa';
expect(doc.getElementById('feature-public-url').textContent).to.equal(
expect(doc.getElementById('feature-public-url').textContent).toBe(
`${prefix}.`
);
expect(
doc.querySelector('head link[rel="shortcut icon"]').getAttribute('href')
).to.equal(`${prefix}/favicon.ico`);
).toBe(`${prefix}/favicon.ico`);
});

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

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

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

expect(doc.getElementById('feature-expand-env-1').textContent).to.equal(
expect(doc.getElementById('feature-expand-env-1').textContent).toBe(
'basic'
);
expect(doc.getElementById('feature-expand-env-2').textContent).to.equal(
expect(doc.getElementById('feature-expand-env-2').textContent).toBe(
'basic'
);
expect(doc.getElementById('feature-expand-env-3').textContent).to.equal(
expect(doc.getElementById('feature-expand-env-3').textContent).toBe(
'basic'
);
expect(
doc.getElementById('feature-expand-env-existing').textContent
).to.equal('fromtheshell');
).toBe('fromtheshell');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const fs = require('fs');
const http = require('http');
const jsdom = require('jsdom');
const path = require('path');
const { expect } = require('chai');

let getMarkup;
let resourceLoader;
Expand Down Expand Up @@ -52,7 +51,7 @@ if (process.env.E2E_FILE) {
() => {
expect(
new Error("This isn't the error you are looking for.")
).to.be.undefined();
).toBeUndefined();
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

import { expect } from 'chai';
import initDOM from './initDOM';

describe('Integration', () => {
Expand All @@ -15,119 +14,117 @@ describe('Integration', () => {

expect(
doc.getElementById('feature-array-destructuring').childElementCount
).to.equal(4);
).toBe(4);
});

it('array spread', async () => {
const doc = await initDOM('array-spread');

expect(
doc.getElementById('feature-array-spread').childElementCount
).to.equal(4);
expect(doc.getElementById('feature-array-spread').childElementCount).toBe(
4
);
});

it('async/await', async () => {
const doc = await initDOM('async-await');

expect(
doc.getElementById('feature-async-await').childElementCount
).to.equal(4);
expect(doc.getElementById('feature-async-await').childElementCount).toBe(
4
);
});

it('class properties', async () => {
const doc = await initDOM('class-properties');

expect(
doc.getElementById('feature-class-properties').childElementCount
).to.equal(4);
).toBe(4);
});

it('computed properties', async () => {
const doc = await initDOM('computed-properties');

expect(
doc.getElementById('feature-computed-properties').childElementCount
).to.equal(4);
).toBe(4);
});

it('custom interpolation', async () => {
const doc = await initDOM('custom-interpolation');

expect(
doc.getElementById('feature-custom-interpolation').childElementCount
).to.equal(4);
).toBe(4);
});

it('default parameters', async () => {
const doc = await initDOM('default-parameters');

expect(
doc.getElementById('feature-default-parameters').childElementCount
).to.equal(4);
).toBe(4);
});

it('destructuring and await', async () => {
const doc = await initDOM('destructuring-and-await');

expect(
doc.getElementById('feature-destructuring-and-await').childElementCount
).to.equal(4);
).toBe(4);
});

it('generators', async () => {
const doc = await initDOM('generators');

expect(
doc.getElementById('feature-generators').childElementCount
).to.equal(4);
expect(doc.getElementById('feature-generators').childElementCount).toBe(
4
);
});

it('object destructuring', async () => {
const doc = await initDOM('object-destructuring');

expect(
doc.getElementById('feature-object-destructuring').childElementCount
).to.equal(4);
).toBe(4);
});

it('object spread', async () => {
const doc = await initDOM('object-spread');

expect(
doc.getElementById('feature-object-spread').childElementCount
).to.equal(4);
).toBe(4);
});

it('promises', async () => {
const doc = await initDOM('promises');

expect(doc.getElementById('feature-promises').childElementCount).to.equal(
4
);
expect(doc.getElementById('feature-promises').childElementCount).toBe(4);
});

it('rest + default', async () => {
const doc = await initDOM('rest-and-default');

expect(
doc.getElementById('feature-rest-and-default').childElementCount
).to.equal(4);
).toBe(4);
});

it('rest parameters', async () => {
const doc = await initDOM('rest-parameters');

expect(
doc.getElementById('feature-rest-parameters').childElementCount
).to.equal(4);
).toBe(4);
});

it('template interpolation', async () => {
const doc = await initDOM('template-interpolation');

expect(
doc.getElementById('feature-template-interpolation').childElementCount
).to.equal(4);
).toBe(4);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

import { expect } from 'chai';
import initDOM from './initDOM';

describe('Integration', () => {
Expand All @@ -15,56 +14,56 @@ describe('Integration', () => {

expect(
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
).to.match(/html\{/);
).toMatch(/html\{/);
expect(
doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '')
).to.match(/#feature-css-inclusion\{background:.+;color:.+}/);
).toMatch(/#feature-css-inclusion\{background:.+;color:.+}/);
});

it('image inclusion', async () => {
const doc = await initDOM('image-inclusion');

expect(doc.getElementById('feature-image-inclusion').src).to.match(
expect(doc.getElementById('feature-image-inclusion').src).toMatch(
/^data:image\/jpeg;base64.+==$/
);
});

it('no ext inclusion', async () => {
const doc = await initDOM('no-ext-inclusion');

expect(doc.getElementById('feature-no-ext-inclusion').href).to.match(
expect(doc.getElementById('feature-no-ext-inclusion').href).toMatch(
/\/static\/media\/aFileWithoutExt\.[a-f0-9]{8}\.bin$/
);
});

it('json inclusion', async () => {
const doc = await initDOM('json-inclusion');

expect(doc.getElementById('feature-json-inclusion').textContent).to.equal(
expect(doc.getElementById('feature-json-inclusion').textContent).toBe(
'This is an abstract.'
);
});

it('linked modules', async () => {
const doc = await initDOM('linked-modules');

expect(doc.getElementById('feature-linked-modules').textContent).to.equal(
expect(doc.getElementById('feature-linked-modules').textContent).toBe(
'2.0.0'
);
});

it('svg inclusion', async () => {
const doc = await initDOM('svg-inclusion');

expect(doc.getElementById('feature-svg-inclusion').src).to.match(
expect(doc.getElementById('feature-svg-inclusion').src).toMatch(
/\/static\/media\/logo\..+\.svg$/
);
});

it('unknown ext inclusion', async () => {
const doc = await initDOM('unknown-ext-inclusion');

expect(doc.getElementById('feature-unknown-ext-inclusion').href).to.match(
expect(doc.getElementById('feature-unknown-ext-inclusion').href).toMatch(
/\/static\/media\/aFileWithExt\.[a-f0-9]{8}\.unknown$/
);
});
Expand Down
12 changes: 8 additions & 4 deletions tasks/e2e-kitchensink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,17 @@ E2E_URL="http://localhost:3001" \
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
CI=true NODE_PATH=src \
NODE_ENV=development \
node_modules/.bin/mocha --require babel-register --require babel-polyfill integration/*.test.js
BABEL_ENV=test \
node_modules/.bin/jest "integration(/|\\)*.test.*"

# Test "production" environment
E2E_FILE=./build/index.html \
CI=true \
NODE_PATH=src \
NODE_ENV=production \
BABEL_ENV=test \
PUBLIC_URL=http://www.example.org/spa/ \
node_modules/.bin/mocha --require babel-register --require babel-polyfill integration/*.test.js
node_modules/.bin/jest "integration(/|\\)*.test.*"

# ******************************************************************************
# Finally, let's check that everything still works after ejecting.
Expand Down Expand Up @@ -285,15 +287,17 @@ E2E_URL="http://localhost:3002" \
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
CI=true NODE_PATH=src \
NODE_ENV=development \
node_modules/.bin/mocha --require babel-register --require babel-polyfill integration/*.test.js
BABEL_ENV=test \
node_modules/.bin/jest "integration(/|\\)*.test.*"

# Test "production" environment
E2E_FILE=./build/index.html \
CI=true \
NODE_ENV=production \
BABEL_ENV=test \
NODE_PATH=src \
PUBLIC_URL=http://www.example.org/spa/ \
node_modules/.bin/mocha --require babel-register --require babel-polyfill integration/*.test.js
node_modules/.bin/jest "integration(/|\\)*.test.*"

# Cleanup
cleanup