diff --git a/.eslintignore b/.eslintignore index a0a3ac6..b5d9e67 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,7 +1,3 @@ dist/ -config/ coverage/ node_modules/ -lib/ -es/ -umd/ diff --git a/.eslintrc b/.eslintrc index 83ec572..61193cb 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,20 +1,87 @@ { - "env": {}, - "extends": ["airbnb", "plugin:jest/recommended"], + "parserOptions": { + "ecmaVersion": 2022, + "sourceType": "module", + "ecmaFeatures": { + "jsx": true + } + }, + "extends": [ + "airbnb", + "plugin:react/recommended", + "plugin:react-hooks/recommended", + "plugin:testing-library/react" + ], "globals": { - "document": true + "page": true, + "document": true, + "vi": true }, - "parser": "@babel/eslint-parser", - "plugins": ["babel", "jest", "react", "react-hooks"], + "plugins": [ + "react", + "react-hooks", + "testing-library" + ], "rules": { + "import/no-unresolved": [ + 2, { "ignore": ["test-utils"] } + ], "import/prefer-default-export": "off", - "import/no-extraneous-dependencies": "off", - "no-console": "warn", + "no-console": "off", + "no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true }], + "no-unused-vars": "off", + "no-undef": "off", + "no-restricted-syntax": ["warn", "WithStatement"], + "no-restricted-globals": ["error"], + "eqeqeq": ["warn", "smart"], + "no-use-before-define": [ + "warn", + { + "functions": false, + "classes": false, + "variables": false + }, + ], + "no-mixed-operators": [ + "warn", + { + "groups": [ + ["&", "|", "^", "~", "<<", ">>", ">>>"], + ["==", "!=", "===", "!==", ">", ">=", "<", "<="], + ["&&", "||"], + ["in", "instanceof"], + ], + "allowSamePrecedence": false, + }, + ], "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], - "react/jsx-fragments": "off", - "react/jsx-props-no-spreading": "off", + "no-underscore-dangle": "off", "react/prefer-stateless-function": "off", + "react/jsx-props-no-spreading": "off", "react/function-component-definition": "off", - "react/require-default-props": "off" + "default-param-last": "off", + "arrow-parens": "off", + "import/no-anonymous-default-export": "off", + "import/no-extraneous-dependencies": "off", + "max-len": ["error", { + "code": 120, + "ignoreComments": true, + "ignoreStrings": true, + "ignoreTemplateLiterals": true, + "ignoreRegExpLiterals": true + }], + "react/jsx-uses-react": "off", + "react/react-in-jsx-scope": "off", + "react/require-default-props": [2, { + "functions": "defaultArguments" + }], + "react-hooks/exhaustive-deps": "error", + "testing-library/render-result-naming-convention": "off", + "testing-library/no-render-in-lifecycle": [ + "error", + { + "allowTestingFrameworkSetupHook": "beforeEach" + } + ] } } diff --git a/README.md b/README.md index 220948f..8eaab8c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # mirador-dl-plugin -[![Travis][build-badge]][build] [![npm package][npm-badge]][npm] [![Coveralls][coveralls-badge]][coveralls] @@ -10,10 +9,6 @@ ![mirador-download-options](https://user-images.githubusercontent.com/5402927/87057857-3d056e80-c1bc-11ea-8860-7662208c19fa.png) - -[build-badge]: https://img.shields.io/travis/projectmirador/mirador-dl-plugin/main.png?style=flat-square -[build]: https://travis-ci.org/projectmirador/mirador-dl-plugin - [npm-badge]: https://img.shields.io/npm/v/mirador-dl-plugin.png?style=flat-square [npm]: https://www.npmjs.org/package/mirador-dl-plugin diff --git a/__tests__/CanvasDownloadLinks.test.js b/__tests__/CanvasDownloadLinks.test.js index d436d20..e0696f7 100644 --- a/__tests__/CanvasDownloadLinks.test.js +++ b/__tests__/CanvasDownloadLinks.test.js @@ -44,7 +44,7 @@ describe('CanvasDownloadLinks', () => { let currentBoundsSpy; beforeEach(() => { - currentBoundsSpy = jest.spyOn(CanvasDownloadLinks.prototype, 'currentBounds'); + currentBoundsSpy = vi.spyOn(CanvasDownloadLinks.prototype, 'currentBounds'); }); afterEach(() => { @@ -197,8 +197,8 @@ describe('CanvasDownloadLinks', () => { describe('For Images Less Than 1000px Wide', () => { it('does not render a smaller version link if image is under 1000px wide', () => { - canvas.getWidth = () => 999; - createWrapper({ canvas }); + const smallCanvas = { ...canvas, getWidth: () => 999 }; + createWrapper({ canvas: smallCanvas }); const links = screen.getAllByRole('link'); expect(links).toHaveLength(2); // Should only show full-size version and link to PDF. diff --git a/__tests__/MiradorDownloadDialog.test.js b/__tests__/MiradorDownloadDialog.test.js index 85eb6ac..7bc5796 100644 --- a/__tests__/MiradorDownloadDialog.test.js +++ b/__tests__/MiradorDownloadDialog.test.js @@ -49,7 +49,7 @@ describe('Dialog', () => { }); it('calls the closeDialog function when the close button is clicked', async () => { - const closeDialog = jest.fn(); + const closeDialog = vi.fn(); createWrapper({ closeDialog }); const closeButton = await screen.findByText(/mirador-dl-plugin\.close/); fireEvent.click(closeButton); diff --git a/__tests__/miradorDownloadPlugin.test.js b/__tests__/miradorDownloadPlugin.test.js index b691986..ab79377 100644 --- a/__tests__/miradorDownloadPlugin.test.js +++ b/__tests__/miradorDownloadPlugin.test.js @@ -28,8 +28,8 @@ describe('miradorDownloadPlugin', () => { describe('MenuItem', () => { it('triggers both openDownloadDialog and handleClose when "Download" is clicked', async () => { - const handleClose = jest.fn(); - const openDownloadDialog = jest.fn(); + const handleClose = vi.fn(); + const openDownloadDialog = vi.fn(); createWrapper({ handleClose, openDownloadDialog }); const openDownloadDialogButton = await screen.findByText(/mirador-dl-plugin\.download/); fireEvent.click(openDownloadDialogButton); diff --git a/babel.config.js b/babel.config.js deleted file mode 100644 index d2c9247..0000000 --- a/babel.config.js +++ /dev/null @@ -1,93 +0,0 @@ -const moduleFormatMap = { - cjs: 'commonjs', - es: false, -}; - -module.exports = (api) => ({ - presets: [ - api.env('test') && [ - '@babel/preset-env', - { - modules: 'commonjs', - targets: { - node: 'current', - }, - }, - ], - (api.env('production') || api.env('development')) && [ - '@babel/preset-env', - { - corejs: 3, - exclude: ['transform-typeof-symbol'], - forceAllTransforms: true, - modules: moduleFormatMap[process.env.MODULE_FORMAT] || false, - useBuiltIns: 'entry', - }, - ], - [ - '@babel/preset-react', - { - development: api.env('development') || api.env('test'), - runtime: 'automatic', - useBuiltIns: true, - }, - ], - ].filter(Boolean), - plugins: [ - 'babel-plugin-macros', - '@babel/plugin-transform-destructuring', - [ - '@babel/plugin-proposal-class-properties', - { - loose: true, - }, - ], - ['@babel/plugin-proposal-private-property-in-object', { loose: true }], - ['@babel/plugin-proposal-private-methods', { loose: true }], - [ - '@babel/plugin-proposal-object-rest-spread', - { - useBuiltIns: true, - }, - ], - [ - '@babel/plugin-transform-runtime', - { - corejs: false, - helpers: false, // Needed to support IE/Edge - regenerator: true, - }, - ], - [ - '@babel/plugin-transform-regenerator', - { - async: false, - }, - ], - ['transform-react-remove-prop-types', - { - ignoreFilenames: ['node_modules'], - removeImport: true, - }, - ], - [ - '@emotion', - { - importMap: { - '@mui/system': { - styled: { - canonicalImport: ['@emotion/styled', 'default'], - styledBaseImport: ['@mui/system', 'styled'], - }, - }, - '@mui/material/styles': { - styled: { - canonicalImport: ['@emotion/styled', 'default'], - styledBaseImport: ['@mui/material/styles', 'styled'], - }, - }, - }, - }, - ], - ].filter(Boolean), -}); diff --git a/demo/src/index.html b/demo/src/index.html index 4f8170c..51c3c81 100644 --- a/demo/src/index.html +++ b/demo/src/index.html @@ -6,6 +6,6 @@
- +