Skip to content

Commit

Permalink
chore: upgrade to Jest v29 (#2289)
Browse files Browse the repository at this point in the history
* chore: upgrade to Jest v29

* fix: visual tests globals

* test: try bumping timeout
  • Loading branch information
emmenko authored Sep 19, 2022
1 parent aa185a1 commit 2750e66
Show file tree
Hide file tree
Showing 81 changed files with 934 additions and 850 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {
globals: {
page: true,
HOST: true,
globalThis: true,
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: yarn typecheck

- name: Running linters and tests
run: yarn run jest --projects jest.{eslint,stylelint,test,ts-test,bundle}.config.js --reporters jest-silent-reporter
run: yarn run jest --projects jest.{eslint,stylelint,test,ts-test,bundle}.config.js --reporters github-actions
env:
CI: true

Expand Down
14 changes: 7 additions & 7 deletions generators/package-json/test/generate-package-json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ describe('when package.json is NOT private', () => {
options
);
expect(content).toMatchInlineSnapshot(`
Object {
{
"bugs": "https://github.com/commercetools/ui-kit/issues",
"description": "Render an Avenger",
"homepage": "https://uikit.commercetools.com",
"keywords": Array [
"keywords": [
"javascript",
"typescript",
"design-system",
Expand All @@ -55,18 +55,18 @@ describe('when package.json is NOT private', () => {
"main": "dist/avenger.cjs.js",
"module": "dist/avenger.esm.js",
"name": "@commercetools-uikit/avenger",
"peerDependencies": Object {
"peerDependencies": {
"react": "16.8.x",
},
"publishConfig": Object {
"publishConfig": {
"access": "public",
},
"readme": Object {
"componentPaths": Array [
"readme": {
"componentPaths": [
"./src/avenger.js",
],
},
"repository": Object {
"repository": {
"directory": "packages/avenger",
"type": "git",
"url": "https://github.com/commercetools/ui-kit.git",
Expand Down
6 changes: 3 additions & 3 deletions generators/readme/test/generate-readme.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('generate README (for JS file)', () => {
\`\`\`jsx
import Avenger from '@commercetools-uikit/avenger';
const Example = () => <Avenger name=\\"Dr. Strange\\" />;
const Example = () => <Avenger name="Dr. Strange" />;
export default Example;
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('generate README (for JS file)', () => {
## More information
This section should come AFTER the \\"Properties\\".
This section should come AFTER the "Properties".
"
`);
}, 10000);
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('generate README (for TS file)', () => {
\`\`\`jsx
import JusticeLeague from '@commercetools-uikit/justice-league';
const Example = () => <JusticeLeague name=\\"Batman\\" />;
const Example = () => <JusticeLeague name="Batman" />;
export default Example;
Expand Down
6 changes: 4 additions & 2 deletions jest.bundle.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (!info) {
}

/**
* @type {import('@jest/types').Config.ProjectConfig}
* @type {import('jest').Config}
*/
module.exports = {
displayName: 'bundle',
Expand All @@ -45,7 +45,9 @@ module.exports = {
rootDir: rootPath,
setupFiles: ['<rootDir>/test/setup-tests.js', 'jest-localstorage-mock'],
testEnvironment: 'jsdom',
testURL: 'https://mc.commercetools.com/',
testEnvironmentOptions: {
url: 'https://mc.europe-west1.gcp.commercetools.com',
},
testPathIgnorePatterns: ['node_modules'],
testRegex: '\\.bundlespec\\.js$',
transform: {
Expand Down
2 changes: 1 addition & 1 deletion jest.eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @type {import('@jest/types').Config.ProjectConfig}
* @type {import('jest').Config}
*/
module.exports = {
runner: 'jest-runner-eslint',
Expand Down
2 changes: 1 addition & 1 deletion jest.stylelint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @type {import('@jest/types').Config.ProjectConfig}
* @type {import('jest').Config}
*/
module.exports = {
runner: 'jest-runner-stylelint',
Expand Down
8 changes: 5 additions & 3 deletions jest.test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ process.env.ENABLE_NEW_JSX_TRANSFORM = 'true';
const rootPath = process.cwd();

/**
* @type {import('@jest/types').Config.ProjectConfig}
* @type {import('jest').Config}
*/
module.exports = {
displayName: 'test',
Expand Down Expand Up @@ -32,9 +32,11 @@ module.exports = {
clearMocks: true,
rootDir: rootPath,
setupFiles: ['<rootDir>/test/setup-tests.js', 'jest-localstorage-mock'],
setupFilesAfterEnv: ['<rootDir>/scripts/setup-test-framework.js'],
setupFilesAfterEnv: ['<rootDir>/test/setup-test-framework.js'],
testEnvironment: 'jsdom',
testURL: 'https://mc.commercetools.com/',
testEnvironmentOptions: {
url: 'https://mc.europe-west1.gcp.commercetools.com',
},
testPathIgnorePatterns: ['generators', '/node_modules/'],
testRegex: '\\.spec\\.[j|t]sx?$',
moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'],
Expand Down
2 changes: 1 addition & 1 deletion jest.ts-test.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
process.env.ENABLE_NEW_JSX_TRANSFORM = 'true';

/**
* @type {import('@jest/types').Config.ProjectConfig}
* @type {import('jest').Config}
*/
module.exports = {
preset: 'ts-jest',
Expand Down
4 changes: 3 additions & 1 deletion jest.visual.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
process.env.ENABLE_NEW_JSX_TRANSFORM = 'true';

/**
* @type {import('@jest/types').Config.ProjectConfig}
* @type {import('jest').Config}
*/
module.exports = {
preset: 'jest-puppeteer',
Expand All @@ -12,4 +12,6 @@ module.exports = {
globals: {
HOST: 'http://localhost:3000',
},
setupFiles: ['<rootDir>/test/setup-globals.js'],
watchPlugins: ['jest-watch-typeahead/filename'],
};
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@commitlint/cli": "17.1.2",
"@commitlint/config-conventional": "17.1.0",
"@formatjs/cli": "5.1.0",
"@formatjs/intl-relativetimeformat": "10.0.1",
"@formatjs/intl-relativetimeformat": "11.1.3",
"@manypkg/cli": "0.19.1",
"@manypkg/get-packages": "1.1.3",
"@percy/cli": "1.8.1",
Expand All @@ -89,10 +89,9 @@
"@testing-library/react": "12.1.5",
"@testing-library/react-hooks": "8.0.1",
"@types/is-hotkey": "^0.1.7",
"@types/jest": "27.5.2",
"@typescript-eslint/eslint-plugin": "5.37.0",
"@typescript-eslint/parser": "5.37.0",
"babel-jest": "27.5.1",
"babel-jest": "29.0.3",
"babel-loader": "8.2.5",
"babel-plugin-typescript-to-proptypes": "1.4.2",
"browserslist": "4.21.4",
Expand All @@ -109,14 +108,15 @@
"husky": "8.0.1",
"identity-obj-proxy": "3.0.0",
"intl-pluralrules": "1.3.1",
"jest": "27.5.1",
"jest-localstorage-mock": "2.4.21",
"jest": "29.0.3",
"jest-environment-jsdom": "29.0.3",
"jest-localstorage-mock": "2.4.22",
"jest-puppeteer": "6.1.1",
"jest-runner-eslint": "1.0.1",
"jest-runner-stylelint": "2.3.7",
"jest-silent-reporter": "0.5.0",
"jest-validate": "27.5.1",
"jest-watch-typeahead": "2.0.0",
"jest-validate": "29.0.3",
"jest-watch-typeahead": "2.2.0",
"lint-staged": "13.0.3",
"moment": "2.29.4",
"moment-timezone": "0.5.37",
Expand Down Expand Up @@ -144,7 +144,7 @@
"stylelint-config-prettier": "9.0.3",
"stylelint-config-standard": "26.0.0",
"stylelint-order": "5.0.0",
"ts-jest": "27.1.5",
"ts-jest": "29.0.1",
"ts-node": "10.9.1",
"tsc-files": "1.1.3",
"typescript": "4.8.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/components/avatar/src/avatar.visualspec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import percySnapshot from '@percy/puppeteer';

describe('Avatar', () => {
beforeAll(async () => {
await page.goto(`${HOST}/avatar`);
await page.goto(`${globalThis.HOST}/avatar`);
});

it('Default', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import percySnapshot from '@percy/puppeteer';

describe('FlatButton', () => {
beforeAll(async () => {
await page.goto(`${HOST}/flat-button`);
await page.goto(`${globalThis.HOST}/flat-button`);
});

it('Default', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import percySnapshot from '@percy/puppeteer';

describe('IconButton', () => {
beforeAll(async () => {
await page.goto(`${HOST}/icon-button`);
await page.goto(`${globalThis.HOST}/icon-button`);
});

it('Default', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import percySnapshot from '@percy/puppeteer';

describe('PrimaryButton', () => {
beforeAll(async () => {
await page.goto(`${HOST}/primary-button`);
await page.goto(`${globalThis.HOST}/primary-button`);
});

it('Default', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getDocument, queries } from 'pptr-testing-library';

describe('SecondaryButton', () => {
beforeAll(async () => {
await page.goto(`${HOST}/secondary-button`);
await page.goto(`${globalThis.HOST}/secondary-button`);
});

it('Default', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import percySnapshot from '@percy/puppeteer';

describe('SecondaryIconButton', () => {
beforeAll(async () => {
await page.goto(`${HOST}/secondary-icon-button`);
await page.goto(`${globalThis.HOST}/secondary-icon-button`);
});

it('Default', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/card/src/card.visualspec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import percySnapshot from '@percy/puppeteer';

describe('Card', () => {
beforeAll(async () => {
await page.goto(`${HOST}/card`);
await page.goto(`${globalThis.HOST}/card`);
});

it('Default', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import percySnapshot from '@percy/puppeteer';

describe('CollapsiblePanel', () => {
beforeAll(async () => {
await page.goto(`${HOST}/collapsible-panel`);
await page.goto(`${globalThis.HOST}/collapsible-panel`);
});

it('Default', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import percySnapshot from '@percy/puppeteer';

describe('Constraints.Horizontal', () => {
beforeAll(async () => {
await page.goto(`${HOST}/constraints-horizontal`);
await page.goto(`${globalThis.HOST}/constraints-horizontal`);
});

it('Default', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import percySnapshot from '@percy/puppeteer';

describe('DataTable', () => {
beforeAll(async () => {
await page.goto(`${HOST}/data-table`);
await page.goto(`${globalThis.HOST}/data-table`);
});

it('Default', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import percySnapshot from '@percy/puppeteer';

describe('FieldLabel', () => {
beforeAll(async () => {
await page.goto(`${HOST}/field-label`);
await page.goto(`${globalThis.HOST}/field-label`);
});

it('Default', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { getDocument, queries } from 'pptr-testing-library';

describe('AsyncCreatableSelectField', () => {
it('Default', async () => {
await page.goto(`${HOST}/async-creatable-select-field`);
await page.goto(`${globalThis.HOST}/async-creatable-select-field`);
const doc = await getDocument(page);
const select = await queries.findAllByLabelText(doc, 'State');
await expect(select).toBeTruthy();
await percySnapshot(page, 'AsyncCreatableSelectField');
});
describe('with defaultOptions', () => {
it('When open', async () => {
await page.goto(`${HOST}/async-creatable-select-field/interaction`);
await page.goto(
`${globalThis.HOST}/async-creatable-select-field/interaction`
);
const doc = await getDocument(page);
const selects = await queries.findAllByLabelText(doc, 'State');
const select = selects[0];
Expand All @@ -22,7 +24,7 @@ describe('AsyncCreatableSelectField', () => {
describe('without defaultOptions', () => {
it('When open', async () => {
await page.goto(
`${HOST}/async-creatable-select-field/interaction/without-default-options`
`${globalThis.HOST}/async-creatable-select-field/interaction/without-default-options`
);
const doc = await getDocument(page);
const selects = await queries.findAllByLabelText(doc, 'State');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getDocument, queries } from 'pptr-testing-library';

describe('AsyncSelectField', () => {
it('Default', async () => {
await page.goto(`${HOST}/async-select-field`);
await page.goto(`${globalThis.HOST}/async-select-field`);
const doc = await getDocument(page);
const selects = await queries.findAllByLabelText(doc, 'State');
await expect(selects).toBeTruthy();
Expand All @@ -12,7 +12,7 @@ describe('AsyncSelectField', () => {

describe('with defaultOptions', () => {
it('Open', async () => {
await page.goto(`${HOST}/async-select-field/interaction`);
await page.goto(`${globalThis.HOST}/async-select-field/interaction`);
const doc = await getDocument(page);
const selects = await queries.findAllByLabelText(doc, 'State');
const select = selects[0];
Expand All @@ -24,7 +24,7 @@ describe('AsyncSelectField', () => {
describe('without defaultOptions', () => {
it('Open', async () => {
await page.goto(
`${HOST}/async-select-field/interaction/without-default-options`
`${globalThis.HOST}/async-select-field/interaction/without-default-options`
);
const doc = await getDocument(page);
const selects = await queries.findAllByLabelText(doc, 'State');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import percySnapshot from '@percy/puppeteer';

describe('CreatableSelectField', () => {
beforeAll(async () => {
await page.goto(`${HOST}/creatable-select-field`);
await page.goto(`${globalThis.HOST}/creatable-select-field`);
});

it('Default', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import percySnapshot from '@percy/puppeteer';

describe('DateField', () => {
beforeAll(async () => {
await page.goto(`${HOST}/date-field`);
await page.goto(`${globalThis.HOST}/date-field`);
});

it('DateField', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import percySnapshot from '@percy/puppeteer';

describe('DateRangeField', () => {
beforeAll(async () => {
await page.goto(`${HOST}/date-range-field`);
await page.goto(`${globalThis.HOST}/date-range-field`);
});

it('Default', async () => {
Expand Down
Loading

1 comment on commit 2750e66

@vercel
Copy link

@vercel vercel bot commented on 2750e66 Sep 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.