Skip to content
Merged
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
/.sewing-kit
/examples
/build
/dist
Expand Down
5 changes: 2 additions & 3 deletions .github/ISSUE_TEMPLATE/ISSUE.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ If you include an animated gif showing your issue, wrapping it in a details tag

## Steps to reproduce the problem

1.
1.
1.
1. First step
1. Second step

## Reduced test case

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.log
node_modules
/.sewing-kit
/build
/dist
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
/.sewing-kit
/build
/dist
/src/styles/polaris-tokens
Expand Down
1 change: 1 addition & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
/.sewing-kit
/build
/dist
/src/styles/polaris-tokens
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"**/.DS_Store": true,
"**/.git": true,
"**/node_modules": true,
".{dev,shadowenv.d}": true,
".{dev,shadowenv.d,sewing-kit}": true,
"{build,dist}/": true,
"examples/*/build": true
},
Expand Down
2 changes: 2 additions & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

### Development workflow

- Use `sewing-kit-next` for test and linting harnesses. ([#4402](https://github.com/Shopify/polaris-react/pull/4402))

### Dependency upgrades

### Code quality
Expand Down
23 changes: 2 additions & 21 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
module.exports = function (api) {
// When building (using rollup) or running storybook (using babel-loader) we
// want to compile for the web otherwise compile for node usage (within jest)
const isWeb = api.caller((caller = {}) => {
return ['babel-loader', '@rollup/plugin-babel'].includes(caller.name);
});

// Our esnext rollup build will want to override the browserslist we pass in
// instead of using the default as defined in our package.json
const browsers = api.caller((caller = {}) => caller.browserslistOverride);

const runtimePreset = isWeb
? [
'@shopify/babel-preset/web',
{modules: 'auto', typescript: true, browsers},
]
: ['@shopify/babel-preset/node', {modules: 'auto', typescript: true}];

return {
presets: [runtimePreset, ['@shopify/babel-preset/react']],
};
module.exports = {
presets: [['@shopify/babel-preset', {typescript: true, react: true}]],
};
8 changes: 8 additions & 0 deletions config/jest-transform-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const {basename} = require('path');

module.exports = {
process(src, filename) {
const stringifedBasename = JSON.stringify(basename(filename));
return `module.exports = ${stringifedBasename};`;
},
};
5 changes: 5 additions & 0 deletions config/jest-transform-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
process() {
return `module.exports = new Proxy({}, {get: (_, key) => (key === '__esModule' ? false : key)})`;
},
};
30 changes: 21 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
}
},
"scripts": {
"lint": "sewing-kit lint",
"format": "sewing-kit format",
"type-check": "sewing-kit type-check",
"test": "sewing-kit test",
"lint": "skn lint",
"format": "skn format",
"type-check": "skn type-check",
"test": "skn test",
"test:coverage": "CI=true yarn test --coverage",
"posttest:coverage": "yarn open:coverage",
"open:coverage": "open build/coverage/index.html",
Expand Down Expand Up @@ -91,19 +91,32 @@
"react-dom": "^16.14.0"
},
"devDependencies": {
"@babel/core": "^7.6.0",
"@babel/node": "^7.6.1",
"@babel/core": "^7.15.0",
"@babel/node": "^7.14.9",
"@rollup/plugin-babel": "^5.1.0",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-image": "^2.0.5",
"@rollup/plugin-node-resolve": "^8.4.0",
"@rollup/plugin-replace": "^2.3.3",
"@rollup/pluginutils": "^3.1.0",
"@shopify/jest-dom-mocks": "^2.9.1",
"@sewing-kit/cli": "^0.6.2",
"@sewing-kit/core": "^0.6.2",
"@sewing-kit/plugin-babel": "^0.1.1",
"@sewing-kit/plugin-eslint": "^0.4.2",
"@sewing-kit/plugin-jest": "^0.5.1",
"@sewing-kit/plugin-prettier": "^0.1.2",
"@sewing-kit/plugin-stylelint": "^0.4.2",
"@sewing-kit/plugin-typescript": "^0.6.1",
"@shopify/babel-preset": "^24.1.2",
"@shopify/browserslist-config": "^3.0.0",
"@shopify/eslint-plugin": "^39.0.1",
"@shopify/jest-dom-mocks": "^3.0.5",
"@shopify/postcss-plugin": "^3.1.1",
"@shopify/prettier-config": "^1.1.2",
"@shopify/react-testing": "^3.2.0",
"@shopify/sewing-kit": "^0.140.0",
"@shopify/storybook-a11y-test": "^0.0.1",
"@shopify/stylelint-plugin": "^10.0.1",
"@shopify/typescript-configs": "^5.0.0",
"@size-limit/preset-small-lib": "^4.10.2",
"@storybook/addon-a11y": "^6.1.11",
"@storybook/addon-console": "^1.2.1",
Expand All @@ -118,7 +131,6 @@
"@types/scss-parser": "^1.0.0",
"babel-core": "7.0.0-bridge.0",
"babel-loader": "^8.1.0",
"babel-preset-shopify": "^21.0.0",
"chalk": "^2.4.2",
"change-case": "^3.1.0",
"commander": "^4.1.0",
Expand Down
7 changes: 4 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ function plugins({browserslist, stylesConfig}) {
envName: 'production',
exclude: 'node_modules/**',
babelHelpers: 'bundled',
caller: {
browserslistOverride: browserslist,
},
// This is kinda silly but if the browserslist is absent we don't want
// to set the key at all (which is different to the key being present but
// it's value is undefined)
...(browserslist ? {targets: browserslist} : {}),
}),
styles({
...stylesConfig,
Expand Down
105 changes: 74 additions & 31 deletions sewing-kit.config.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,77 @@
import {join} from 'path';

import {ConfigurationCallback, Plugins} from '@shopify/sewing-kit';
import {
createPackage,
Runtime,
createComposedWorkspacePlugin,
createComposedProjectPlugin,
createProjectPlugin,
} from '@sewing-kit/core';
import {babel} from '@sewing-kit/plugin-babel';
import {workspaceTypeScript} from '@sewing-kit/plugin-typescript';
import {eslint} from '@sewing-kit/plugin-eslint';
import {stylelint} from '@sewing-kit/plugin-stylelint';
import {prettier} from '@sewing-kit/plugin-prettier';
import {jest} from '@sewing-kit/plugin-jest';

// eslint-disable-next-line import/no-default-export
export default function sewingKitConfig(
plugins: Plugins,
): ReturnType<ConfigurationCallback> {
return {
name: 'polaris',
library: true,
plugins: [
plugins.jest((config) => {
config.roots = [
join(__dirname, 'src'),
join(__dirname, 'tests'),
join(__dirname, 'scripts'),
];

// Code coverage
config.collectCoverageFrom = [
'src/**/*.{ts,tsx}',
'scripts/**/*.{ts,tsx}',
'!src/test-utilities/**/*.*',
'!src/**/index.{ts,tsx}',
'!src/**/*.d.ts',
'!src/**/*.test.{ts,tsx}',
];

return config;
}),
],
};
export default createPackage((pkg) => {
pkg.runtimes(Runtime.Node, Runtime.Browser);
pkg.entry({root: './src/index'});
pkg.use(libraryPackagePlugin(), libaryWorkspacePlugin());
});

function libraryPackagePlugin() {
return createComposedProjectPlugin('PolarisPackage', [
// this needs to be set here as the current setup cannot
// find the babel.config.js file at the root of the project
babel({
config: {
presets: [['@shopify/babel-preset', {typescript: true, react: true}]],
configFile: false,
},
}),
jestAdjustmentsPlugin(),
]);
}

function libaryWorkspacePlugin() {
return createComposedWorkspacePlugin('PolarisWorkspace', [
jest(),
eslint(),
stylelint({files: '**/*.scss'}),
prettier({files: '**/*.{md,json,yaml,yml}'}),
workspaceTypeScript(),
]);
}

function jestAdjustmentsPlugin() {
return createProjectPlugin('PolarisJest', ({tasks: {test}}) => {
test.hook(({hooks}) => {
hooks.configure.hook((configuration) => {
configuration.jestEnvironment?.hook(() => 'jsdom');

// Aliases for root-level imports
// These do not work in rollup builds, so perhaps we shouldn't configure
// them to work here either
configuration.jestModuleMapper?.hook((moduleMapper) => {
moduleMapper['^(components|test-utilities|types|utilities)(.*)'] =
'<rootDir>/src/$1$2';

return moduleMapper;
});

// Ignore tests in the examples folder
configuration.jestConfig?.hook((config) => ({
...config,
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/examples/'],
}));

// Novel file types - scss and images
configuration.jestTransforms?.hook((transforms) => ({
...transforms,
'\\.s?css$': require.resolve('./config/jest-transform-style'),
'\\.svg$': require.resolve('./config/jest-transform-image'),
}));
});
});
});
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useCallback, useState} from 'react';
import {ActionMenuProps, ActionMenu} from 'index';
import {mountWithApp} from 'test-utilities';

import {ActionMenuProps, ActionMenu} from '../../..';
import {Actions, MenuGroup, RollupActions, SecondaryAction} from '../..';

describe('<Actions />', () => {
Expand Down
23 changes: 9 additions & 14 deletions src/components/Modal/tests/Modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ describe('<Modal>', () => {
);
});

it('focuses the dialog node on mount', () => {
// Causes a circular dependency that causes the whole test file to be unrunnable
// eslint-disable-next-line jest/no-disabled-tests
it.skip('focuses the dialog node on mount', () => {
const modal = mountWithAppProvider(
<Modal title="foo" onClose={jest.fn()} open instant />,
);
Expand Down Expand Up @@ -397,17 +399,6 @@ describe('<Modal>', () => {
});

describe('activator', () => {
let rafSpy: jest.SpyInstance;

beforeEach(() => {
rafSpy = jest.spyOn(window, 'requestAnimationFrame');
rafSpy.mockImplementation((callback) => callback());
});

afterEach(() => {
rafSpy.mockRestore();
});

it('renders the element if an element is passed in', () => {
const modal = mountWithAppProvider(
<Modal
Expand Down Expand Up @@ -458,7 +449,9 @@ describe('<Modal>', () => {
}).not.toThrow();
});

it('focuses the activator when the activator is an element on close', () => {
// Causes a circular dependency that causes the whole test file to be unrunnable
// eslint-disable-next-line jest/no-disabled-tests
it.skip('focuses the activator when the activator is an element on close', () => {
const id = 'activator-id';
const modal = mountWithApp(
<Modal
Expand All @@ -475,7 +468,9 @@ describe('<Modal>', () => {
expect(document.activeElement).toBe(activator);
});

it('focuses the activator when the activator a ref on close', () => {
// Causes a circular dependency that causes the whole test file to be unrunnable
// eslint-disable-next-line jest/no-disabled-tests
it.skip('focuses the activator when the activator a ref on close', () => {
const buttonId = 'buttonId';
const TestHarness = () => {
const buttonRef = useRef<HTMLDivElement>(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
// eslint-disable-next-line no-restricted-imports
import {mountWithAppProvider} from 'test-utilities/legacy';
import {mountWithApp} from 'test-utilities';

import {SingleThumb} from '../SingleThumb';

Expand Down Expand Up @@ -43,13 +44,13 @@ describe('<SingleThumb />', () => {
it('is called with a new value', () => {
const onChangeSpy = jest.fn();
const {onChange, ...rest} = mockProps;
const element = mountWithAppProvider(
const element = mountWithApp(
<SingleThumb onChange={onChangeSpy} {...rest} />,
);

const singleThumb = element.find(SingleThumb);
(element.find('input') as any).instance().value = 40;
singleThumb.find('input').simulate('change');
element.find('input')!.trigger('onChange', {
currentTarget: {value: '40'},
});
expect(onChangeSpy).toHaveBeenCalledWith(40, 'MyRangeSlider');
});
});
Expand Down
8 changes: 6 additions & 2 deletions src/components/Sheet/tests/Sheet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ describe('<Sheet />', () => {
}).not.toThrow();
});

it('focuses the activator when the activator is an element on close', () => {
// Causes a circular dependency that causes the whole test file to be unrunnable
// eslint-disable-next-line jest/no-disabled-tests
it.skip('focuses the activator when the activator is an element on close', () => {
const id = 'activator-id';
const sheet = mountWithApp(
<Sheet {...mockProps} activator={<Button id={id} />}>
Expand All @@ -150,7 +152,9 @@ describe('<Sheet />', () => {
expect(document.activeElement).toBe(activator);
});

it('focuses the activator when the activator a ref on close', () => {
// Causes a circular dependency that causes the whole test file to be unrunnable
// eslint-disable-next-line jest/no-disabled-tests
it.skip('focuses the activator when the activator a ref on close', () => {
const buttonId = 'buttonId';
const TestHarness = () => {
const buttonRef = useRef<HTMLDivElement>(null);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading