Skip to content
This repository was archived by the owner on Feb 22, 2021. It is now read-only.

Commit 795acb9

Browse files
committed
test(check): improve test case
1 parent 75ef2f1 commit 795acb9

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

test/mocha.opts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
--recursive
33
--require ./node_modules/ts-node/register
44
--ui bdd
5+
--check-leaks
56
--timeout 60000
67
--watch-extensions ts
78
test/**/*.ts

test/utils/check.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
11
import * as Check from '../../src/utils/check'
22
import { expect } from 'chai'
33

4-
describe('Utils function', () => {
4+
describe('Utils function test', () => {
55

6-
it('pages should return false and print warning', done => {
7-
const result = Check.pages(['123'])
8-
expect(result).to.eq(false)
9-
done()
6+
let _warn: (msg?: any, ...p: any[]) => void
7+
before(() => {
8+
// hack warn func, utils function maybe use it
9+
_warn = global.console.warn
10+
global.console.warn = () => {}
1011
})
1112

12-
it('link should return false and print warning', done => {
13-
const result = Check.scripts(['123'])
14-
expect(result).to.eq(false)
15-
done()
13+
after(() => {
14+
global.console.warn = _warn
15+
})
16+
17+
it('should return boolean and identify page url', () => {
18+
expect(Check.pages(['http://baidu.com'])).to.be.eq(true)
19+
expect(Check.pages(['https://baidu.com'])).to.be.eq(true)
20+
expect(Check.pages(['//baidu.com'])).to.be.eq(true)
21+
expect(Check.pages(['baidu.com'])).to.be.eq(false)
22+
expect(Check.pages(['www.baidu.com'])).to.be.eq(false)
23+
expect(Check.pages([''])).to.be.eq(false)
24+
})
25+
26+
it('should return boolean and identify script url', () => {
27+
expect(Check.scripts(['http://npm.some.js'])).to.be.eq(true)
28+
expect(Check.scripts(['https://npm.some.js'])).to.be.eq(true)
29+
expect(Check.scripts(['//npm.some.js'])).to.be.eq(true)
30+
expect(Check.scripts(['https://npm.some.css'])).to.be.eq(false)
31+
expect(Check.scripts(['https://npm.some.com/'])).to.be.eq(false)
32+
expect(Check.scripts(['hello.npm.some.com'])).to.be.eq(false)
33+
expect(Check.scripts([''])).to.be.eq(false)
34+
})
35+
36+
it('should return boolean and identify all options', () => {
1637
})
1738

1839
})

0 commit comments

Comments
 (0)