Skip to content

Commit

Permalink
Migrate from jest to mocha + chai (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
remusao authored Apr 14, 2020
1 parent e8485d9 commit b130034
Show file tree
Hide file tree
Showing 34 changed files with 1,133 additions and 2,172 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- name: Bootstrap
run: yarn bootstrap

- name: Build
run: yarn build

- name: Bundle
run: yarn bundle

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
run: yarn bootstrap

- name: Build
run: yarn build

- name: Bundle
run: yarn bundle

- name: Lint
Expand Down
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
.nyc_output
coverage/
dist/
node_modules/

packages/*/build/
packages/*/dist/
packages/*/node_modules/
packages/*/coverage/

bench/requests.json
9 changes: 9 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
timeout: 10000,
reporter: 'spec',
require: ['ts-node/register'],
retries: 2,
color: false,
extension: ['ts'],
recursive: true,
};
9 changes: 0 additions & 9 deletions jest.config.js

This file was deleted.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
],
"scripts": {
"bootstrap": "yarn install --frozen-lock && lerna bootstrap",
"bundle": "lerna run --concurrency 1 bundle",
"build": "tsc --build ./tsconfig.project.json && lerna run build",
"watch": "tsc --build ./tsconfig.project.json --watch",
"bundle": "lerna run --concurrency 2 bundle",
"clean": "lerna run --parallel clean && lerna clean --yes && rimraf node_modules",
"lint": "lerna run --parallel lint",
"test": "lerna run --concurrency 1 test",
"test": "lerna run --concurrency 2 test",
"bench": "make -C bench",
"update": "git submodule foreach git pull origin master && ts-node -O '{\"module\": \"commonjs\"}' ./bin/update.ts",
"release": "auto shipit"
Expand Down
6 changes: 0 additions & 6 deletions packages/tldts-core/jest.config.js

This file was deleted.

15 changes: 8 additions & 7 deletions packages/tldts-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@
"clean": "rimraf dist",
"lint": "tslint --config ../../tslint.json --project ./tsconfig.json",
"build": "tsc --build ./tsconfig.json",
"bundle": "rollup --config ./rollup.config.ts",
"prebundle": "yarn run build",
"bundle": "tsc --build ./tsconfig.bundle.json && rollup --config ./rollup.config.ts",
"prepack": "yarn run bundle",
"test": "jest --config ./jest.config.js ./test/"
"test": "nyc mocha --config ../../.mocharc.js"
},
"devDependencies": {
"@types/jest": "^25.1.0",
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"@types/node": "^13.1.0",
"jest": "^25.1.0",
"chai": "^4.2.0",
"mocha": "^7.1.1",
"nyc": "^15.0.1",
"rimraf": "^3.0.0",
"rollup": "^2.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"rollup-plugin-sourcemaps": "^0.5.0",
"ts-jest": "^25.0.0",
"tslint": "^6.0.0",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.5.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/tldts-core/rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import resolve from 'rollup-plugin-node-resolve';
import resolve from '@rollup/plugin-node-resolve';
import sourcemaps from 'rollup-plugin-sourcemaps';

export default {
Expand Down
73 changes: 38 additions & 35 deletions packages/tldts-core/test/tldts.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { expect } from 'chai';
import 'mocha';

import isIp from '../src/is-ip';
import isValidHostname from '../src/is-valid';

Expand All @@ -11,23 +14,23 @@ function repeat(str: string, n: number): string {

describe('#isIp', () => {
it('should return false on incorrect inputs', () => {
expect(isIp('')).toEqual(false);
expect(isIp('')).to.equal(false);
});

it('should return true on valid ip addresses', () => {
expect(isIp('::1')).toEqual(true);
expect(isIp('2001:0db8:85a3:0000:0000:8a2e:0370:7334')).toEqual(true);
expect(isIp('192.168.0.1')).toEqual(true);
expect(isIp('[::1]')).toEqual(true);
expect(isIp('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]')).toEqual(true);
expect(isIp('::1')).to.equal(true);
expect(isIp('2001:0db8:85a3:0000:0000:8a2e:0370:7334')).to.equal(true);
expect(isIp('192.168.0.1')).to.equal(true);
expect(isIp('[::1]')).to.equal(true);
expect(isIp('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]')).to.equal(true);
});

it('should return false on invalid ip addresses', () => {
expect(isIp('::1-')).toEqual(false);
expect(isIp('192.168.0.1.')).toEqual(false);
expect(isIp('192.168.0')).toEqual(false);
expect(isIp('192.168.0.')).toEqual(false);
expect(isIp('192.16-8.0.1')).toEqual(false);
expect(isIp('::1-')).to.equal(false);
expect(isIp('192.168.0.1.')).to.equal(false);
expect(isIp('192.168.0')).to.equal(false);
expect(isIp('192.168.0.')).to.equal(false);
expect(isIp('192.16-8.0.1')).to.equal(false);
});
});

Expand All @@ -39,47 +42,47 @@ describe('#isValidHostname', () => {
}

it('should detect valid hostname', () => {
expect(isValidHostname('')).toEqual(false);
expect(isValidHostname('-google.com')).toEqual(false);
expect(isValidHostname('google-.com')).toEqual(false);
expect(isValidHostname('google.com-')).toEqual(false);
expect(isValidHostname('.google.com')).toEqual(false);
expect(isValidHostname('google..com')).toEqual(false);
expect(isValidHostname('google.com..')).toEqual(false);
expect(isValidHostname('example.' + repeat('a', 64) + '.')).toEqual(false);
expect(isValidHostname('example.' + repeat('a', 64))).toEqual(false);
expect(isValidHostname('googl@.com..')).toEqual(false);
expect(isValidHostname('')).to.equal(false);
expect(isValidHostname('-google.com')).to.equal(false);
expect(isValidHostname('google-.com')).to.equal(false);
expect(isValidHostname('google.com-')).to.equal(false);
expect(isValidHostname('.google.com')).to.equal(false);
expect(isValidHostname('google..com')).to.equal(false);
expect(isValidHostname('google.com..')).to.equal(false);
expect(isValidHostname('example.' + repeat('a', 64) + '.')).to.equal(false);
expect(isValidHostname('example.' + repeat('a', 64))).to.equal(false);
expect(isValidHostname('googl@.com..')).to.equal(false);

// Length of 256 (too long)
expect(isValidHostname(maxSizeHostname + 'a')).toEqual(false);
expect(isValidHostname(maxSizeHostname + 'a')).to.equal(false);

expect(isValidHostname('google.com')).toEqual(true);
expect(isValidHostname('miam.google.com')).toEqual(true);
expect(isValidHostname('miam.miam.google.com')).toEqual(true);
expect(isValidHostname('example.' + repeat('a', 63) + '.')).toEqual(true);
expect(isValidHostname('example.' + repeat('a', 63))).toEqual(true);
expect(isValidHostname('google.com')).to.equal(true);
expect(isValidHostname('miam.google.com')).to.equal(true);
expect(isValidHostname('miam.miam.google.com')).to.equal(true);
expect(isValidHostname('example.' + repeat('a', 63) + '.')).to.equal(true);
expect(isValidHostname('example.' + repeat('a', 63))).to.equal(true);

// Accepts domains with '_' (validation is not strict)
expect(isValidHostname('foo.bar_baz.com')).toEqual(true);
expect(isValidHostname('foo.bar_baz.com')).to.equal(true);

// @see https://github.com/oncletom/tld.js/issues/95
expect(isValidHostname('miam.miam.google.com.')).toEqual(true);
expect(isValidHostname('miam.miam.google.com.')).to.equal(true);

// Length of 255 (maximum allowed)
expect(isValidHostname(maxSizeHostname)).toEqual(true);
expect(isValidHostname(maxSizeHostname)).to.equal(true);

// Unicode
expect(isValidHostname('mañana.com')).toEqual(true);
expect(isValidHostname('mañana.com')).to.equal(true);
});

it('should be falsy on invalid domain syntax', () => {
expect(isValidHostname('.localhost')).toEqual(false);
expect(isValidHostname('.google.com')).toEqual(false);
expect(isValidHostname('.com')).toEqual(false);
expect(isValidHostname('.localhost')).to.equal(false);
expect(isValidHostname('.google.com')).to.equal(false);
expect(isValidHostname('.com')).to.equal(false);
});

it('should accept extra code points in domain (not strict)', () => {
// @see https://github.com/oncletom/tld.js/pull/122
expect(isValidHostname('foo.bar_baz.com')).toEqual(true);
expect(isValidHostname('foo.bar_baz.com')).to.equal(true);
});
});
12 changes: 12 additions & 0 deletions packages/tldts-core/tsconfig.bundle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"declaration": false,
"declarationMap": false,
"declarationDir": null,
"composite": false,
"incremental": true,
"module": "es6",
"outDir": "dist/es6"
}
}
8 changes: 4 additions & 4 deletions packages/tldts-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"extends": "../../tsconfig",
"compilerOptions": {
"composite": true,
"declarationDir": "dist/types",
"outDir": "dist/es6"
"outDir": "dist/cjs",
"declarationDir": "dist/types"
},
"include": [
"src/**/*.ts",
"index.ts"
"./src/**/*.ts",
"./index.ts"
]
}
6 changes: 0 additions & 6 deletions packages/tldts-experimental/jest.config.js

This file was deleted.

15 changes: 8 additions & 7 deletions packages/tldts-experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,23 @@
"clean": "rimraf dist coverage",
"lint": "tslint --config ../../tslint.json --project ./tsconfig.json",
"build": "tsc --build ./tsconfig.json",
"bundle": "rollup --config ./rollup.config.ts",
"prebundle": "yarn run build",
"bundle": "tsc --build ./tsconfig.bundle.json && rollup --config ./rollup.config.ts",
"prepack": "yarn run bundle",
"test": "jest --config ./jest.config.js --coverage ./test/"
"test": "mocha --config ../../.mocharc.js"
},
"devDependencies": {
"@ampproject/rollup-plugin-closure-compiler": "^0.25.0",
"@types/jest": "^25.1.0",
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"@types/node": "^13.1.0",
"jest": "^25.1.0",
"chai": "^4.2.0",
"mocha": "^7.1.1",
"nyc": "^15.0.1",
"rimraf": "^3.0.0",
"rollup": "^2.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"rollup-plugin-sourcemaps": "^0.5.0",
"tldts-tests": "^5.6.23",
"ts-jest": "^25.0.0",
"tslint": "^6.0.0",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.5.2"
Expand Down
8 changes: 2 additions & 6 deletions packages/tldts-experimental/rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import compiler from '@ampproject/rollup-plugin-closure-compiler';
import resolve from 'rollup-plugin-node-resolve';
import resolve from '@rollup/plugin-node-resolve';
import sourcemaps from 'rollup-plugin-sourcemaps';

export default [
Expand Down Expand Up @@ -33,10 +33,6 @@ export default [
sourcemap: true,
},
],
plugins: [
resolve(),
compiler(),
sourcemaps(),
],
plugins: [resolve(), compiler(), sourcemaps()],
},
];
10 changes: 3 additions & 7 deletions packages/tldts-experimental/test/publicsuffix.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// @ts-ignore
import * as tldMinified from '../dist/index.umd.min';
import * as tld from '../index';
import 'mocha';

import { publicSuffixListTests } from 'tldts-tests';

import * as tld from '../index';

describe('tldts classic', () => {
publicSuffixListTests(tld.getDomain);
});

describe('tldts minified', () => {
publicSuffixListTests(tldMinified.getDomain);
});
10 changes: 3 additions & 7 deletions packages/tldts-experimental/test/tld.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// @ts-ignore
import * as tldMinified from '../dist/index.umd.min';
import * as tld from '../index';
import 'mocha'

import { tldtsTests } from 'tldts-tests';

import * as tld from '../index';

describe('tldts classic', () => {
tldtsTests(tld);
});

describe('tldts minified', () => {
tldtsTests(tldMinified);
});
12 changes: 12 additions & 0 deletions packages/tldts-experimental/tsconfig.bundle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"declaration": false,
"declarationMap": false,
"declarationDir": null,
"composite": false,
"incremental": true,
"module": "es6",
"outDir": "dist/es6"
}
}
8 changes: 4 additions & 4 deletions packages/tldts-experimental/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"extends": "../../tsconfig",
"compilerOptions": {
"composite": true,
"declarationDir": "dist/types",
"outDir": "dist/es6"
"outDir": "dist/cjs",
"declarationDir": "dist/types"
},
"references": [
{
Expand All @@ -14,7 +14,7 @@
}
],
"include": [
"src/**/*.ts",
"index.ts"
"./src/**/*.ts",
"./index.ts"
]
}
Loading

0 comments on commit b130034

Please sign in to comment.