mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-04-12 14:40:47 +08:00
fix: make test works
This commit is contained in:
parent
0bbacd1b3b
commit
39f2b3c49a
@ -1,12 +1,33 @@
|
||||
// the file is used for jest testing & site building
|
||||
// > 2%, make template string not compiled to concat, since it's not fast
|
||||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
targets: '>2%, not IE 11'
|
||||
}
|
||||
]
|
||||
]
|
||||
presets:
|
||||
process.env.NODE_ENV === 'test'
|
||||
? [
|
||||
['@babel/preset-env', { targets: { node: 'current' } }],
|
||||
[
|
||||
'@babel/preset-typescript',
|
||||
{
|
||||
allExtensions: true,
|
||||
isTSX: true,
|
||||
jsxPragma: 'h',
|
||||
jsxPragmaFrag: 'Fragment'
|
||||
}
|
||||
],
|
||||
[
|
||||
'@babel/preset-react',
|
||||
{
|
||||
pragma: 'h',
|
||||
pragmaFrag: 'Fragment'
|
||||
}
|
||||
]
|
||||
]
|
||||
: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
targets: '>2%, not IE 11'
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
|
@ -18,10 +18,7 @@ module.exports = {
|
||||
collectCoverage: true,
|
||||
|
||||
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
||||
// collectCoverageFrom: [
|
||||
// '<rootDir>/src/**/*.js$',
|
||||
// '<rootDir>/src/**/*.vue$'
|
||||
// ],
|
||||
collectCoverageFrom: ['<rootDir>/src/**/*.(ts|tsx)$'],
|
||||
|
||||
// The directory where Jest should output its coverage files
|
||||
coverageDirectory: 'coverage',
|
||||
@ -34,10 +31,7 @@ module.exports = {
|
||||
],
|
||||
|
||||
// A list of reporter names that Jest uses when writing coverage reports
|
||||
coverageReporters: [
|
||||
'text',
|
||||
'lcov'
|
||||
],
|
||||
coverageReporters: ['text', 'lcov'],
|
||||
|
||||
// An object that configures minimum threshold enforcement for coverage results
|
||||
// coverageThreshold: undefined,
|
||||
@ -66,16 +60,10 @@ module.exports = {
|
||||
// maxWorkers: "50%",
|
||||
|
||||
// An array of directory names to be searched recursively up from the requiring module's location
|
||||
moduleDirectories: [
|
||||
'node_modules'
|
||||
],
|
||||
moduleDirectories: ['node_modules'],
|
||||
|
||||
// An array of file extensions your modules use
|
||||
moduleFileExtensions: [
|
||||
'js',
|
||||
'json',
|
||||
'vue'
|
||||
],
|
||||
moduleFileExtensions: ['js', 'json', 'ts', 'tsx'],
|
||||
|
||||
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
||||
// moduleNameMapper: {},
|
||||
@ -142,13 +130,11 @@ module.exports = {
|
||||
// The glob patterns Jest uses to detect test files
|
||||
testMatch: [
|
||||
// '<rootDir>/src/**/__tests__/**/*.[jt]s',
|
||||
'<rootDir>/src/**/*.(spec|test).[tj]s'
|
||||
'<rootDir>/src/**/*.(spec|test).ts'
|
||||
],
|
||||
|
||||
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
||||
testPathIgnorePatterns: [
|
||||
'/node_modules/'
|
||||
],
|
||||
testPathIgnorePatterns: ['/node_modules/'],
|
||||
|
||||
// The regexp pattern or array of patterns that Jest uses to detect test files
|
||||
// testRegex: [],
|
||||
@ -167,14 +153,11 @@ module.exports = {
|
||||
|
||||
// A map from regular expressions to paths to transformers
|
||||
transform: {
|
||||
'^.+\\.js$': 'babel-jest',
|
||||
'^.+\\.vue$': 'vue-jest'
|
||||
'^.+\\.(j|t)sx?$': 'babel-jest'
|
||||
},
|
||||
|
||||
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
||||
// transformIgnorePatterns: [
|
||||
// "/node_modules/"
|
||||
// ],
|
||||
transformIgnorePatterns: ['<rootDir>/node_modules/(?!lodash-es)'],
|
||||
|
||||
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
||||
// unmockedModulePathPatterns: undefined,
|
||||
|
14
package.json
14
package.json
@ -20,7 +20,7 @@
|
||||
"format:code": "prettier --write \"(src|demo)/**/*.(vue|js)\"",
|
||||
"format:md": "prettier --write --parser markdown --prose-wrap never \"demo/**/*.md\"",
|
||||
"release:package": "npm run build:package && npm publish --tag next",
|
||||
"test": "echo 'pass'",
|
||||
"test": "cross-env NODE_ENV=test jest",
|
||||
"gen-version": "node scripts/gen-version",
|
||||
"tusimple:dev": "npm run generate && cross-env NODE_ENV=development webpack-dev-server --config build/webpack.tusimple-dev.js",
|
||||
"tusimple:build:doc": "npm run generate && npm run build && rm -rf build-doc/dist && cross-env NODE_ENV=production webpack --config build/webpack.tusimple-doc.js",
|
||||
@ -68,10 +68,10 @@
|
||||
"@babel/generator": "^7.12.11",
|
||||
"@babel/parser": "^7.12.11",
|
||||
"@babel/preset-env": "^7.12.10",
|
||||
"@babel/preset-react": "^7.12.13",
|
||||
"@babel/preset-typescript": "^7.12.16",
|
||||
"@babel/traverse": "^7.12.12",
|
||||
"@rollup/plugin-babel": "^5.2.2",
|
||||
"@rollup/plugin-node-resolve": "^10.0.0",
|
||||
"@rollup/plugin-replace": "^2.3.4",
|
||||
"@types/jest": "^26.0.15",
|
||||
"@types/lodash-es": "^4.17.4",
|
||||
"@typescript-eslint/eslint-plugin": "^4.13.0",
|
||||
@ -80,7 +80,7 @@
|
||||
"@vue/compiler-sfc": "^3.0.5",
|
||||
"@vue/eslint-config-standard": "^5.1.2",
|
||||
"@vue/eslint-config-typescript": "^7.0.0",
|
||||
"@vue/test-utils": "^2.0.0-beta.12",
|
||||
"@vue/test-utils": "^2.0.0-rc.1",
|
||||
"autoprefixer": "^9.8.6",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"babel-jest": "^26.6.2",
|
||||
@ -103,12 +103,10 @@
|
||||
"marked": "^1.2.0",
|
||||
"prettier": "^2.2.1",
|
||||
"rollup": "^2.32.1",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"rollup-plugin-vue": "^6.0.0-beta.11",
|
||||
"tinycolor2": "^1.4.2",
|
||||
"typescript": "^4.1.3",
|
||||
"vite": "^2.0.0-beta.64",
|
||||
"vue-jest": "^5.0.0-alpha.5",
|
||||
"vite": "^2.0.0",
|
||||
"vue-jest": "^5.0.0-alpha.7",
|
||||
"vue-router": "^4.0.0-rc.1"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -18,11 +18,13 @@ disabled
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| page-count | `number` | required | |
|
||||
| page-sizes | `Array<number>` | `[]` | |
|
||||
| default-page | `number` | `1` | |
|
||||
| default-page-size | `number` | `10` | |
|
||||
| page-count | `number` | `1` | |
|
||||
| page-sizes | `Array<number>` | `['10']` | |
|
||||
| page-size | `number` | `undefined` | |
|
||||
| page-slot | `number` | `9` | |
|
||||
| page | `number` | required | |
|
||||
| page | `number` | `undefined` | |
|
||||
| show-quick-jumper | `boolean` | `false` | |
|
||||
| show-size-picker | `boolean` | `false` | |
|
||||
| on-update:page | `(page: number) => any` | `undefined` | |
|
||||
|
@ -18,11 +18,13 @@ disabled
|
||||
|
||||
| 名称 | 类型 | 默认值 | 说明 |
|
||||
| ------------------- | --------------------------- | ----------- | ---- |
|
||||
| page-count | `number` | required | |
|
||||
| page-sizes | `Array<number>` | `[]` | |
|
||||
| default-page | `number` | `1` | |
|
||||
| default-page-size | `number` | `10` | |
|
||||
| page-count | `number` | `1` | |
|
||||
| page-sizes | `Array<number>` | `['10']` | |
|
||||
| page-size | `number` | `undefined` | |
|
||||
| page-slot | `number` | `9` | |
|
||||
| page | `number` | required | |
|
||||
| page | `number` | `undefined` | |
|
||||
| show-quick-jumper | `boolean` | `false` | |
|
||||
| show-size-picker | `boolean` | `false` | |
|
||||
| on-update:page | `(page: number) => any` | `undefined` | |
|
||||
|
@ -95,7 +95,7 @@ const paginationProps = {
|
||||
validator: (value: any) => {
|
||||
return Number.isInteger(value) && value > 0
|
||||
},
|
||||
default: undefined
|
||||
default: 1
|
||||
}
|
||||
} as const
|
||||
|
||||
|
@ -94,7 +94,7 @@ function mapPagesToPageItems (pages: number[], currentPage: number): PageItem[]
|
||||
function pageItems (
|
||||
currentPage: number,
|
||||
pageCount: number,
|
||||
pageSlot: number
|
||||
pageSlot?: number
|
||||
): PageItem[] {
|
||||
const pages = pagesToShow(currentPage, pageCount, pageSlot)
|
||||
return mapPagesToPageItems(pages, currentPage)
|
||||
|
@ -1,19 +0,0 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import create from '../../create'
|
||||
import { enUS } from '../../locales'
|
||||
import { paginationLight } from '../styles'
|
||||
import { NPagination } from '../index'
|
||||
|
||||
describe('n-pagination', () => {
|
||||
const naive = create({
|
||||
locales: [enUS],
|
||||
styles: [paginationLight]
|
||||
})
|
||||
it('should work with import on demand', () => {
|
||||
mount(NPagination, {
|
||||
global: {
|
||||
plugins: [naive]
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
8
src/pagination/tests/Pagination.spec.ts
Normal file
8
src/pagination/tests/Pagination.spec.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { NPagination } from '../index'
|
||||
|
||||
describe('n-pagination', () => {
|
||||
it('should work with import on demand', () => {
|
||||
mount(NPagination)
|
||||
})
|
||||
})
|
@ -81,11 +81,13 @@ describe('Pagination', function () {
|
||||
expect(mapPagesToPageItems([-2, -1, 1, 2], 1)).toEqual([
|
||||
{
|
||||
type: 'fastBackward',
|
||||
label: 'fastBackward'
|
||||
label: 'fastBackward',
|
||||
active: false
|
||||
},
|
||||
{
|
||||
type: 'fastForward',
|
||||
label: 'fastForward'
|
||||
label: 'fastForward',
|
||||
active: false
|
||||
},
|
||||
{
|
||||
type: 'page',
|
||||
@ -110,7 +112,8 @@ describe('Pagination', function () {
|
||||
},
|
||||
{
|
||||
type: 'fastBackward',
|
||||
label: 'fastBackward'
|
||||
label: 'fastBackward',
|
||||
active: false
|
||||
},
|
||||
{
|
||||
type: 'page',
|
||||
@ -139,7 +142,8 @@ describe('Pagination', function () {
|
||||
},
|
||||
{
|
||||
type: 'fastForward',
|
||||
label: 'fastForward'
|
||||
label: 'fastForward',
|
||||
active: false
|
||||
},
|
||||
{
|
||||
type: 'page',
|
@ -8,16 +8,18 @@ const createDemoPlugin = require('./build/vite-plugin-demo')
|
||||
module.exports = {
|
||||
root: __dirname,
|
||||
plugins: createDemoPlugin(),
|
||||
alias:
|
||||
resolve: {
|
||||
// In production site build, we want to import naive-ui from node_modules
|
||||
process.env.NODE_ENV !== 'production'
|
||||
? [
|
||||
{
|
||||
find: 'naive-ui',
|
||||
replacement: path.resolve(__dirname, './src')
|
||||
}
|
||||
]
|
||||
: undefined,
|
||||
alias:
|
||||
process.env.NODE_ENV !== 'production'
|
||||
? [
|
||||
{
|
||||
find: 'naive-ui',
|
||||
replacement: path.resolve(__dirname, './src')
|
||||
}
|
||||
]
|
||||
: undefined
|
||||
},
|
||||
define: {
|
||||
'process.env.NODE_ENV': `'${process.env.NODE_ENV}'`,
|
||||
__DEV__: process.env.NODE_ENV !== 'production'
|
||||
|
Loading…
x
Reference in New Issue
Block a user