From c0c99f57129e3cf55d8020256292f0565a5390e0 Mon Sep 17 00:00:00 2001 From: Bart Riepe Date: Wed, 14 Feb 2024 14:03:55 +0900 Subject: [PATCH] chore: switch to vite and vitest for examples and tests --- .eslintrc | 13 - .github/workflows/release.yml | 27 +- .github/workflows/test.yml | 25 - .prettierrc | 4 - LICENSE | 2 +- examples/index.html | 25 + examples/src/index.tsx | 21 +- examples/src/style.scss | 9 + examples/vite.config.ts | 4 + jest.config.js | 5 - package.json | 70 +- pnpm-lock.yaml | 9060 +++++++------------------------ src/global.d.ts | 9 + src/index.tsx | 13 +- test/compute-lines.test.ts | 38 +- test/react-diff-viewer.test.tsx | 12 +- tsconfig.esm.json | 11 + tsconfig.json | 6 +- vitest.config.ts | 5 + webpack.config.js | 60 - 20 files changed, 2056 insertions(+), 7363 deletions(-) delete mode 100644 .eslintrc delete mode 100644 .github/workflows/test.yml delete mode 100644 .prettierrc create mode 100644 examples/index.html create mode 100644 examples/vite.config.ts delete mode 100644 jest.config.js create mode 100644 src/global.d.ts create mode 100644 tsconfig.esm.json create mode 100644 vitest.config.ts delete mode 100644 webpack.config.js diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index c552a63e..00000000 --- a/.eslintrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": ["airbnb-base", "plugin:@typescript-eslint/recommended"], - "rules": { - "@typescript-eslint/indent": ["error", 2], - "arrow-body-style": "off", - "import/extensions": "off" - }, - "env": { - "mocha": true, - "node": true, - "browser": true - } -} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 03ffeb49..9bda6a53 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,12 +1,31 @@ -name: Release +name: Test & Release on: push: - branches: - - master - - next + jobs: + test: + name: Unit tests + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 'lts/*' + - uses: pnpm/action-setup@v2.2.4 + with: + version: latest + - name: Install dependencies + run: pnpm i + - name: Run unit tests + run: pnpm run test release: name: Release + needs: test + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/next' runs-on: ubuntu-latest steps: - name: Checkout diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 0cba4f2c..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Test -on: - push: - pull_request: - -jobs: - release: - name: Unit tests - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: 'lts/*' - - uses: pnpm/action-setup@v2.2.4 - with: - version: latest - - name: Install dependencies - run: pnpm i - - name: Run unit tests - run: pnpm run test diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index a20502b7..00000000 --- a/.prettierrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "singleQuote": true, - "trailingComma": "all" -} diff --git a/LICENSE b/LICENSE index e460037a..18ad6af7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Pranesh Ravi +Copyright (c) 2023 Bart Riepe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/examples/index.html b/examples/index.html new file mode 100644 index 00000000..b137fa3f --- /dev/null +++ b/examples/index.html @@ -0,0 +1,25 @@ + + + + + + React Diff Viewer + + + + + + + + + + + + + +
+ + + + + diff --git a/examples/src/index.tsx b/examples/src/index.tsx index 88b0dda3..84c4b53a 100644 --- a/examples/src/index.tsx +++ b/examples/src/index.tsx @@ -6,14 +6,14 @@ import logo from '../../logo.png'; import cn from 'classnames'; import {render} from "react-dom"; -const oldJs = require('./diff/javascript/old.rjs').default; -const newJs = require('./diff/javascript/new.rjs').default; +import oldJs from './diff/javascript/old.rjs?raw'; +import newJs from './diff/javascript/new.rjs?raw'; -const oldYaml = require('./diff/massive/old.yaml').default; -const newYaml = require('./diff/massive/new.yaml').default; +import oldYaml from './diff/massive/old.yaml?raw'; +import newYaml from './diff/massive/new.yaml?raw'; -const oldJson = require('./diff/json/old.json'); -const newJson = require('./diff/json/new.json'); +import oldJson from './diff/json/old.json'; +import newJson from './diff/json/new.json'; interface ExampleState { splitView?: boolean; @@ -75,11 +75,11 @@ class Example extends Component<{}, ExampleState> { }; public render(): JSX.Element { - let oldValue = '', newValue = ''; - if (this.state.dataType == 'json') { + let oldValue: string | object = '' + let newValue: string | object = ''; + if (this.state.dataType === 'json') { oldValue = oldJson newValue = newJson - } else if (this.state.dataType === 'javascript') { oldValue = oldJs newValue = newJs @@ -107,6 +107,9 @@ class Example extends Component<{}, ExampleState> { Featuring split view, inline view, word diff, line highlight and more.

+

+ This documentation is for the `next` release branch, e.g. v4.x +