Browse Source

test: add istanbul ignore to some file and update jest exclude config

走鹃 3 years ago
parent
commit
591051eb86

+ 5 - 2
jest.config.js

@@ -53,8 +53,11 @@ let config = {
         '!packages/**/_story/**',
         '!packages/**/_story/**',
         "!packages/**/getBabelConfig.js",
         "!packages/**/getBabelConfig.js",
         "!packages/**/gulpfile.js",
         "!packages/**/gulpfile.js",
-        "!packages/**/webpack.config.js"
-
+        "!packages/**/webpack.config.js",
+        "!packages/semi-ui/index.ts",
+        '!packages/**/_test_/**',
+        '!packages/**/dist/**',
+        '!packages/semi-ui/locale/**',
     ], // 哪些文件需要收集覆盖率信息
     ], // 哪些文件需要收集覆盖率信息
     coverageDirectory: '<rootDir>/test/coverage', // 输出覆盖信息文件的目录
     coverageDirectory: '<rootDir>/test/coverage', // 输出覆盖信息文件的目录
     coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/packages/*/index.js'], // 统计覆盖信息时需要忽略的文件
     coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/packages/*/index.js'], // 统计覆盖信息时需要忽略的文件

+ 5 - 1
nyc.config.js

@@ -15,6 +15,10 @@ module.exports = {
         "packages/**/_story/**",
         "packages/**/_story/**",
         "packages/**/getBabelConfig.js",
         "packages/**/getBabelConfig.js",
         "packages/**/gulpfile.js",
         "packages/**/gulpfile.js",
-        "packages/**/webpack.config.js"
+        "packages/**/webpack.config.js",
+        "packages/semi-ui/index.ts",
+        'packages/**/_test_/**',
+        'packages/**/dist/**',
+        'packages/semi-ui/locale/**',
     ]
     ]
 };
 };

+ 6 - 0
packages/semi-foundation/base/foundation.ts

@@ -25,6 +25,7 @@ export interface DefaultAdapter<P = Record<string, any>, S = Record<string, any>
 
 
 class BaseFoundation<T extends Partial<DefaultAdapter<P, S>>, P = Record<string, any>, S = Record<string, any>> {
 class BaseFoundation<T extends Partial<DefaultAdapter<P, S>>, P = Record<string, any>, S = Record<string, any>> {
     /** @return enum{css className} */
     /** @return enum{css className} */
+    /* istanbul ignore next */
     static get cssClasses() {
     static get cssClasses() {
         // Classes extending Foundation should implement this method to return an object which exports every
         // Classes extending Foundation should implement this method to return an object which exports every
         // CSS class the foundation class needs as a property. e.g. {ACTIVE: 'component--active'}
         // CSS class the foundation class needs as a property. e.g. {ACTIVE: 'component--active'}
@@ -32,6 +33,7 @@ class BaseFoundation<T extends Partial<DefaultAdapter<P, S>>, P = Record<string,
     }
     }
 
 
     /** @return enum{strings} */
     /** @return enum{strings} */
+    /* istanbul ignore next */
     static get strings() {
     static get strings() {
         // Classes extending Foundation should implement this method to return an object which exports all
         // Classes extending Foundation should implement this method to return an object which exports all
         // semantic strings as constants. e.g. {ARIA_ROLE: 'tablist'}
         // semantic strings as constants. e.g. {ARIA_ROLE: 'tablist'}
@@ -39,6 +41,7 @@ class BaseFoundation<T extends Partial<DefaultAdapter<P, S>>, P = Record<string,
     }
     }
 
 
     /** @return enum{numbers} */
     /** @return enum{numbers} */
+    /* istanbul ignore next */
     static get numbers() {
     static get numbers() {
         // Classes extending Foundation should implement this method to return an object which exports all
         // Classes extending Foundation should implement this method to return an object which exports all
         // of its semantic numbers as constants. e.g. {ANIMATION_DELAY_MS: 350}
         // of its semantic numbers as constants. e.g. {ANIMATION_DELAY_MS: 350}
@@ -91,10 +94,12 @@ class BaseFoundation<T extends Partial<DefaultAdapter<P, S>>, P = Record<string,
         return this._adapter.getContext(key);
         return this._adapter.getContext(key);
     }
     }
 
 
+    /* istanbul ignore next */
     getContexts() {
     getContexts() {
         return this._adapter.getContexts();
         return this._adapter.getContexts();
     }
     }
 
 
+    /* istanbul ignore next */
     getCaches() {
     getCaches() {
         return this._adapter.getCaches();
         return this._adapter.getCaches();
     }
     }
@@ -132,6 +137,7 @@ class BaseFoundation<T extends Partial<DefaultAdapter<P, S>>, P = Record<string,
         // Subclasses should override this method to perform de-initialization routines (de-registering events, etc.)
         // Subclasses should override this method to perform de-initialization routines (de-registering events, etc.)
     }
     }
 
 
+    /* istanbul ignore next */
     log(text: string, ...rest: any) {
     log(text: string, ...rest: any) {
         log(text, ...rest);
         log(text, ...rest);
     }
     }

+ 3 - 0
packages/semi-foundation/timePicker/utils/localeDate.ts

@@ -1,5 +1,6 @@
 import { format as dateFnsFormat, parse as dateFnsParse } from 'date-fns';
 import { format as dateFnsFormat, parse as dateFnsParse } from 'date-fns';
 
 
+/* istanbul ignore next */
 const replace = function replace(str, replacements) {
 const replace = function replace(str, replacements) {
     let _str = str;
     let _str = str;
     for (const key of Object.keys(replacements)) {
     for (const key of Object.keys(replacements)) {
@@ -11,6 +12,7 @@ const replace = function replace(str, replacements) {
     return _str;
     return _str;
 };
 };
 
 
+/* istanbul ignore next */
 export function localeFormat(date, format, locale = {}, options = {}) {
 export function localeFormat(date, format, locale = {}, options = {}) {
     let str = dateFnsFormat(date, format, options);
     let str = dateFnsFormat(date, format, options);
 
 
@@ -19,6 +21,7 @@ export function localeFormat(date, format, locale = {}, options = {}) {
     return str;
     return str;
 }
 }
 
 
+/* istanbul ignore next */
 export function localeParse(dateString, format, locale = {}, defaultDate = null, options = {}) {
 export function localeParse(dateString, format, locale = {}, defaultDate = null, options = {}) {
     // const invertedLocale = invert(locale);
     // const invertedLocale = invert(locale);
 
 

+ 4 - 0
packages/semi-foundation/utils/Logger.ts

@@ -24,18 +24,22 @@ class Logger {
         }
         }
     }
     }
 
 
+    /* istanbul ignore next */
     log(...args: any[]) {
     log(...args: any[]) {
         this._baseLog('log', ...args);
         this._baseLog('log', ...args);
     }
     }
 
 
+    /* istanbul ignore next */
     warn(...args: any[]) {
     warn(...args: any[]) {
         this._baseLog('warn', ...args);
         this._baseLog('warn', ...args);
     }
     }
 
 
+    /* istanbul ignore next */
     error(...args: any[]) {
     error(...args: any[]) {
         this._baseLog('error', ...args);
         this._baseLog('error', ...args);
     }
     }
 
 
+    /* istanbul ignore next */
     info(...args: any[]) {
     info(...args: any[]) {
         this._baseLog('info', ...args);
         this._baseLog('info', ...args);
     }
     }

+ 1 - 0
packages/semi-foundation/utils/Store.ts

@@ -1,3 +1,4 @@
+/* istanbul ignore next */
 class Store<T = Record<string, any>> {
 class Store<T = Record<string, any>> {
     _state: T;
     _state: T;
     _listeners: any[];
     _listeners: any[];

+ 2 - 0
packages/semi-foundation/utils/date-fns-extra.ts

@@ -87,6 +87,7 @@ export const toIANA = (tz: string | number) => {
  * @param {string} [options.timeZone]
  * @param {string} [options.timeZone]
  * @returns {Date}
  * @returns {Date}
  */
  */
+/* istanbul ignore next */
 const parse = (date: string | number | Date, formatToken: string, options?: any) => {
 const parse = (date: string | number | Date, formatToken: string, options?: any) => {
     if (typeof date === 'string') {
     if (typeof date === 'string') {
         date = dateFnsParse(date, formatToken, new Date(), options);
         date = dateFnsParse(date, formatToken, new Date(), options);
@@ -106,6 +107,7 @@ const parse = (date: string | number | Date, formatToken: string, options?: any)
  * @param {object} [options]
  * @param {object} [options]
  * @param {string} [options.timeZone]
  * @param {string} [options.timeZone]
  */
  */
+/* istanbul ignore next */
 const format = (date: string | number | Date, formatToken: string, options?: any) => {
 const format = (date: string | number | Date, formatToken: string, options?: any) => {
     if (options && options.timeZone != null && options.timeZone !== '') {
     if (options && options.timeZone != null && options.timeZone !== '') {
         const timeZone = toIANA(options.timeZone);
         const timeZone = toIANA(options.timeZone);

+ 1 - 0
packages/semi-foundation/utils/isElement.ts

@@ -1,3 +1,4 @@
+/* istanbul ignore next */
 export default function isElement(obj: any) {
 export default function isElement(obj: any) {
     try {
     try {
         // Using W3 DOM2 (works for FF, Opera and Chrome)
         // Using W3 DOM2 (works for FF, Opera and Chrome)

+ 1 - 0
packages/semi-foundation/utils/isEscPress.ts

@@ -1,6 +1,7 @@
 import { get } from 'lodash';
 import { get } from 'lodash';
 import { ESC_KEY } from './keyCode';
 import { ESC_KEY } from './keyCode';
 
 
+/* istanbul ignore next */
 function isEscPress<T extends { key: string }>(e: T) {
 function isEscPress<T extends { key: string }>(e: T) {
     return get(e, 'key') === ESC_KEY ? true : false;
     return get(e, 'key') === ESC_KEY ? true : false;
 }
 }

+ 1 - 0
packages/semi-foundation/utils/set.ts

@@ -1,5 +1,6 @@
 import { isSet } from 'lodash';
 import { isSet } from 'lodash';
 
 
+/* istanbul ignore next */
 export function copySet<T = unknown>(setA: Iterable<T>) {
 export function copySet<T = unknown>(setA: Iterable<T>) {
     return new Set(setA);
     return new Set(setA);
 }
 }