Skip to content

Commit

Permalink
test: add umd test
Browse files Browse the repository at this point in the history
  • Loading branch information
07akioni committed Aug 31, 2022
1 parent 15a75e2 commit b557833
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {
}
},
{
files: '*.spec.ts',
files: ['*.spec.ts', '*.spec.js'],
globals: {
describe: 'readonly',
it: 'readonly',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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=\"<rootDir>/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",
Expand Down
20 changes: 20 additions & 0 deletions umd-test/index.spec.js
Original file line number Diff line number Diff line change
@@ -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')
})
})
3 changes: 3 additions & 0 deletions umd-test/setupVue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as Vue from 'vue'

window.Vue = Vue

0 comments on commit b557833

Please sign in to comment.