Skip to content

Commit

Permalink
Enables JSX and TSX for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsov committed Oct 11, 2023
1 parent e14d20e commit 4734813
Show file tree
Hide file tree
Showing 19 changed files with 245 additions and 106 deletions.
12 changes: 12 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path');
module.exports = {
extends: [
'plugin:@shopify/typescript',
'plugin:@shopify/react',
'plugin:@shopify/jest',
'plugin:@shopify/prettier',
],
Expand All @@ -13,6 +14,9 @@ module.exports = {
},
rules: {
'jest/valid-title': 'off',
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off',
'react/jsx-filename-extension': [1, {extensions: ['.jsx', '.tsx']}],
},
settings: {
'import/resolver': {
Expand All @@ -24,4 +28,12 @@ module.exports = {
},
},
},
overrides: [
{
files: ['./**/*.test.{jsx,tsx}'],
rules: {
'@shopify/jsx-no-hardcoded-content': 'off',
},
},
],
};
7 changes: 7 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = function (api) {
const envName = api.env();
const development = envName === 'development' || envName === 'test';

api.cache(true);

return {
Expand All @@ -8,6 +11,10 @@ module.exports = function (api) {
{useBuiltIns: 'entry', corejs: '3.0', bugfixes: true},
],
['@babel/preset-typescript'],
[
'@babel/preset-react',
{development, useBuiltIns: true, runtime: 'automatic'},
],
],
plugins: [['@babel/plugin-proposal-decorators', {version: '2023-05'}]],
assumptions: {
Expand Down
9 changes: 7 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const {TextEncoder} = require('util');

module.exports = {
testEnvironment: 'jsdom',
testMatch: ['<rootDir>/src/**/*.test.(js|ts)'],
testMatch: ['<rootDir>/src/**/*.test.(js|jsx|ts|tsx)'],
setupFiles: ['<rootDir>/test/environment.ts'],
setupFilesAfterEnv: ['<rootDir>/test/setup.ts'],
transform: {
'\\.(ts|js)': ['babel-jest'],
},
moduleFileExtensions: ['js', 'ts'],
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
collectCoverageFrom: [
'src/**/*.{js,ts}',
'!src/**/*/index.{js,ts}',
Expand All @@ -18,4 +20,7 @@ module.exports = {
coverageDirectory: './coverage/',
collectCoverage: true,
moduleDirectories: ['node_modules', 'src', 'test'],
globals: {
TextEncoder,
},
};
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@babel/core": "^7.22.20",
"@babel/plugin-proposal-decorators": "^7.23.0",
"@babel/preset-env": "^7.22.20",
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.23.0",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
Expand All @@ -63,6 +64,7 @@
"@shopify/typescript-configs": "^5.1.0",
"@types/jest": "^29.5.5",
"@types/node": "^20.6.3",
"@types/react-dom": "^18.2.13",
"concurrently": "^3.5.1",
"esdoc": "^1.1.0",
"esdoc-ecmascript-proposal-plugin": "^1.0.0",
Expand All @@ -71,6 +73,8 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"prettier": "^3.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rollup": "^3.29.3",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-includepaths": "^0.2.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import {createSandbox, waitForRequestAnimationFrame} from 'helper';
import Draggable from '../../..';
import Focusable from '..';

const sampleMarkup = `
<ul class="Container">
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Forth item</li>
<button>Fifth item</button>
</ul>
<div class="Container">
<div tabindex="1"></div>
</div>
`;
const sampleMarkup = (
<>
<ul className="Container">
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Forth item</li>
<button type="button">Fifth item</button>
</ul>
<div className="Container">
<div tabIndex="-1" />
</div>
</>
);

describe('Focusable', () => {
let sandbox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import {
} from '../MirrorEvent';
import Draggable from '../../..';

const sampleMarkup = `
const sampleMarkup = (
<ul>
<li>First item</li>
</ul>
`;
);

describe('Mirror', () => {
let sandbox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {

import DragSensor from '..';

const sampleMarkup = `
const sampleMarkup = (
<ul>
<li class="draggable">First item</li>
<li class="draggable">Second item</li>
<li class="non-draggable">Non draggable item</li>
<li className="draggable">First item</li>
<li className="draggable">Second item</li>
<li className="non-draggable">Non draggable item</li>
</ul>
`;
);

describe('DragSensor', () => {
let sandbox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import {

import MouseSensor from '..';

const sampleMarkup = `
const sampleMarkup = (
<ul>
<li class="draggable">
<div class="handle">First handle</div>
<li className="draggable">
<div className="handle">First handle</div>
First item
</li>
<li class="draggable">
<div class="handle">Second handle</div>
<li className="draggable">
<div className="handle">Second handle</div>
Second item
</li>
<li class="non-draggable">
<div class="handle">Non draggable handle</div>
<li className="non-draggable">
<div className="handle">Non draggable handle</div>
Non draggable item
</li>
</ul>
`;
);

describe('MouseSensor', () => {
let sandbox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import {

import TouchSensor from '..';

const sampleMarkup = `
const sampleMarkup = (
<ul>
<li class="draggable">First item</li>
<li class="draggable">Second item</li>
<li class="non-draggable">Non draggable item</li>
<li className="draggable">First item</li>
<li className="draggable">Second item</li>
<li className="non-draggable">Non draggable item</li>
</ul>
`;
);

describe('TouchSensor', () => {
let sandbox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ import {
import {Focusable, Mirror, Scrollable, Announcement} from '../Plugins';
import {MouseSensor, TouchSensor} from '../Sensors';

const sampleMarkup = `
<ul class="Container">
<li>First item</li>
<li>Second item</li>
</ul>
<ul class="DynamicContainer">
<li>First item</li>
<li>Second item</li>
</ul>
`;
const sampleMarkup = (
<>
<ul className="Container">
<li>First item</li>
<li>Second item</li>
</ul>
<ul className="DynamicContainer">
<li>First item</li>
<li>Second item</li>
</ul>
</>
);

describe('Draggable', () => {
let sandbox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import Droppable, {
DroppableStopEvent,
} from '..';

const sampleMarkup = `
<div class="Container">
<div class="Dropzone isOccupied">
<div class="Draggable"></div>
const sampleMarkup = (
<div className="Container">
<div className="Dropzone isOccupied">
<div className="Draggable" />
</div>
<div class="Dropzone"></div>
<div class="Dropzone isOccupied">
<div class="Draggable"></div>
<div className="Dropzone" />
<div className="Dropzone isOccupied">
<div className="Draggable" />
</div>
<div class="Draggable"></div>
<div className="Draggable" />
</div>
`;
);

describe('Droppable', () => {
let sandbox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import Draggable from '../../../Draggable';
/* eslint-enable @typescript-eslint/ban-ts-comment */
import ResizeMirror from '..';

const sampleMarkup = `
<ul class="Container">
<li>Smaller item</li>
</ul>
<ul class="Container">
<li>Larger item</li>
</ul>
<ul class="Container">
<!-- Empty -->
</ul>
`;
const sampleMarkup = (
<>
<ul className="Container">
<li>Smaller item</li>
</ul>
<ul className="Container">
<li>Larger item</li>
</ul>
<ul className="Container">{/* Empty */}</ul>
</>
);

describe('ResizeMirror', () => {
const smallerDraggableDimensions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ import {

import Sortable from '..';

const sampleMarkup = `
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Forth item</li>
</ul>
<ul>
<li>Fith item</li>
<li>Sixth item</li>
<li>Seventh item</li>
<li>Eighth item</li>
</ul>
`;
const sampleMarkup = (
<>
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Forth item</li>
</ul>
<ul>
<li>Fith item</li>
<li>Sixth item</li>
<li>Seventh item</li>
<li>Eighth item</li>
</ul>
</>
);

describe('Sortable', () => {
let sandbox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ import {

import Swappable from '..';

const sampleMarkup = `
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Forth item</li>
</ul>
<ul>
<li>Fith item</li>
<li>Sixth item</li>
<li>Seventh item</li>
<li>Eighth item</li>
</ul>
`;
const sampleMarkup = (
<>
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Forth item</li>
</ul>
<ul>
<li>Fith item</li>
<li>Sixth item</li>
<li>Seventh item</li>
<li>Eighth item</li>
</ul>
</>
);

describe('Swappable', () => {
let sandbox;
Expand Down
Loading

0 comments on commit 4734813

Please sign in to comment.