From b557833f0477e7a169b2896394a21c7367cf54b3 Mon Sep 17 00:00:00 2001 From: 07akioni <07akioni2@gmail.com> Date: Thu, 1 Sep 2022 00:01:39 +0800 Subject: [PATCH] test: add umd test --- .eslintrc.js | 2 +- package.json | 3 ++- umd-test/index.spec.js | 20 ++++++++++++++++++++ umd-test/setupVue.js | 3 +++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 umd-test/index.spec.js create mode 100644 umd-test/setupVue.js diff --git a/.eslintrc.js b/.eslintrc.js index e8457df70..d186b7ea6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -71,7 +71,7 @@ module.exports = { } }, { - files: '*.spec.ts', + files: ['*.spec.ts', '*.spec.js'], globals: { describe: 'readonly', it: 'readonly', diff --git a/package.json b/package.json index ef49774e2..b8e81d397 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "start": "pnpm run dev", "dev": "pnpm run clean && pnpm run gen-version && pnpm run gen-volar-dts && cross-env NODE_ENV=development vite", - "build:package": "pnpm run gen-version && pnpm run clean && pnpm run gen-volar-dts && tsc -b --force tsconfig.esm.json && node scripts/pre-build/pre-cjs-build.js && tsc -b --force tsconfig.cjs.json && rollup -c && node scripts/post-build && rimraf {es,lib}/*.tsbuildinfo", + "build:package": "pnpm run gen-version && pnpm run clean && pnpm run gen-volar-dts && tsc -b --force tsconfig.esm.json && node scripts/pre-build/pre-cjs-build.js && tsc -b --force tsconfig.cjs.json && rollup -c && pnpm run test:umd && node scripts/post-build && rimraf {es,lib}/*.tsbuildinfo", "build:site": "./scripts/pre-build-site/pre-build-site.sh && cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=4096 vite build && ./scripts/post-build-site/post-build-site.sh", "clean": "rimraf site lib es dist node_modules/naive-ui themes/**/es themes/**/lib", "release:package": "pnpm run test && pnpm run build:package && pnpm publish --no-git-checks", @@ -28,6 +28,7 @@ "test:update": "cross-env NODE_ENV=test jest -u --collectCoverage=false", "test:cov": "cross-env NODE_ENV=test NODE_OPTIONS=--unhandled-rejections=warn jest", "test:watch": "cross-env NODE_ENV=test jest ---watch --verbose --coverage", + "test:umd": "jest --collectCoverage=false --testMatch=\"/umd-test/index.spec.js\"", "gen-version": "node scripts/gen-version", "gen-volar-dts": "esbuild scripts/gen-component-declaration.js --bundle --platform=node --tsconfig=tsconfig.esbuild.json | node", "build:site:ts": "./scripts/pre-build-site/pre-build-site.sh && cross-env TUSIMPLE=true NODE_ENV=production NODE_OPTIONS=--max-old-space-size=4096 vite build && ./scripts/post-build-site/post-build-site.sh", diff --git a/umd-test/index.spec.js b/umd-test/index.spec.js new file mode 100644 index 000000000..d2172ab67 --- /dev/null +++ b/umd-test/index.spec.js @@ -0,0 +1,20 @@ +import './setupVue.js' +import fs from 'fs' +import path from 'path' + +// eslint-disable-next-line n/no-exports-assign +exports = undefined + +// eslint-disable-next-line no-eval +eval( + fs.readFileSync(path.resolve(__dirname, '..', 'dist', 'index.js')).toString() +) + +describe('umd', () => { + it('works', () => { + const div = document.createElement('div') + document.body.appendChild(div) + window.Vue.createApp(window.naive.NDataTable).mount(div) + expect(div.innerHTML).toContain('n-data-table') + }) +}) diff --git a/umd-test/setupVue.js b/umd-test/setupVue.js new file mode 100644 index 000000000..528156637 --- /dev/null +++ b/umd-test/setupVue.js @@ -0,0 +1,3 @@ +import * as Vue from 'vue' + +window.Vue = Vue