Skip tests that use ESM

This commit is contained in:
Tom Coleman 2022-09-28 19:20:26 +10:00
parent 900e7e836d
commit 7e3bd67993
2 changed files with 38 additions and 24 deletions

View File

@ -43,6 +43,19 @@ const annotateWithDocgen = (inputPath: string) => {
return normalizeNewlines(code || '');
};
// We need to skip a set of test cases that use ESM code, as the `requireFromString`
// code below does not support it. These stories will be tested via Chromatic in the
// sandboxes. Hopefully we can figure out a better testing strategy in the future.
const skippedTests = [
'js-class-component',
'js-function-component',
'js-function-component-inline-defaults',
'js-function-component-inline-defaults-no-propTypes',
'ts-function-component',
'ts-function-component-inline-defaults',
'js-proptypes',
];
describe('react component properties', () => {
// Fixture files are in template/stories
const fixturesDir = path.resolve(__dirname, '../../template/stories/__testfixtures__');
@ -51,30 +64,34 @@ describe('react component properties', () => {
const testDir = path.join(fixturesDir, testEntry.name);
const testFile = fs.readdirSync(testDir).find((fileName) => inputRegExp.test(fileName));
if (testFile) {
it(testEntry.name, () => {
const inputPath = path.join(testDir, testFile);
if (skippedTests.includes(testEntry.name)) {
it.skip(testEntry.name, () => {});
} else {
it(testEntry.name, () => {
const inputPath = path.join(testDir, testFile);
// snapshot the output of babel-plugin-react-docgen
const docgenPretty = annotateWithDocgen(inputPath);
expect(docgenPretty).toMatchSpecificSnapshot(path.join(testDir, 'docgen.snapshot'));
// snapshot the output of babel-plugin-react-docgen
const docgenPretty = annotateWithDocgen(inputPath);
expect(docgenPretty).toMatchSpecificSnapshot(path.join(testDir, 'docgen.snapshot'));
// transform into an uglier format that's works with require-from-string
const docgenModule = transformToModule(docgenPretty);
// transform into an uglier format that's works with require-from-string
const docgenModule = transformToModule(docgenPretty);
// snapshot the output of component-properties/react
const { component } = requireFromString(docgenModule, inputPath);
const properties = extractProps(component);
expect(properties).toMatchSpecificSnapshot(path.join(testDir, 'properties.snapshot'));
// snapshot the output of component-properties/react
const { component } = requireFromString(docgenModule, inputPath);
const properties = extractProps(component);
expect(properties).toMatchSpecificSnapshot(path.join(testDir, 'properties.snapshot'));
// snapshot the output of `extractArgTypes`
const argTypes = extractArgTypes(component);
const parameters = { __isArgsStory: true };
const rows = inferControls({
argTypes,
parameters,
} as unknown as StoryContext<AnyFramework>);
expect(rows).toMatchSpecificSnapshot(path.join(testDir, 'argTypes.snapshot'));
});
// snapshot the output of `extractArgTypes`
const argTypes = extractArgTypes(component);
const parameters = { __isArgsStory: true };
const rows = inferControls({
argTypes,
parameters,
} as unknown as StoryContext<AnyFramework>);
expect(rows).toMatchSpecificSnapshot(path.join(testDir, 'argTypes.snapshot'));
});
}
}
}
});

View File

@ -1,8 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`react component properties js-proptypes 1`] = `
"/* eslint-disable react/no-unused-prop-types */
import React from 'react';
"import React from 'react';
import PropTypes, { string, shape } from 'prop-types';
import { PRESET_SHAPE, SOME_PROP_TYPES } from './ext';
const NAMED_OBJECT = {
@ -118,7 +117,6 @@ const SOME_INLINE_DEFAULT_PROPS = {
};
export const PropTypesProps = () => /*#__PURE__*/React.createElement(\\"div\\", null, \\"PropTypes!\\");
PropTypesProps.propTypes = {
// eslint-disable-next-line react/forbid-prop-types
any: PropTypes.any,
bool: PropTypes.bool,
string: PropTypes.string,
@ -168,7 +166,6 @@ PropTypesProps.propTypes = {
* Plain object propType (use shape!!)
*/
obj: PropTypes.object,
// eslint-disable-line react/forbid-prop-types
symbol: PropTypes.symbol,
node: PropTypes.node,
useCustomPropType: customPropType,