From 23dc35d1f195b44bf82b5926880854c649ac747b Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Fri, 12 Apr 2019 22:55:38 +0200 Subject: [PATCH] use test files in js because it is much faster --- __tests__/url.spec.js | 42 ++++++++++++++++++++++++++++++++++++++++++ jest.config.js | 5 +++-- package.json | 1 + 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 __tests__/url.spec.js diff --git a/__tests__/url.spec.js b/__tests__/url.spec.js new file mode 100644 index 00000000..009ee879 --- /dev/null +++ b/__tests__/url.spec.js @@ -0,0 +1,42 @@ +require('./helper') +const expect = require('expect') +const { BaseHistory } = require('../src/history/base') + +const parseURL = BaseHistory.prototype.parseURL + +describe('URL parsing', () => { + it('works with no query no hash', () => { + expect(parseURL('/foo')).toEqual({ + path: '/foo', + hash: '', + query: {}, + }) + }) + + it('extracts the query', () => { + expect(parseURL('/foo?a=one&b=two')).toEqual({ + path: '/foo', + hash: '', + query: { + a: 'one', + b: 'two', + }, + }) + }) + + it('extracts the hash', () => { + expect(parseURL('/foo#bar')).toEqual({ + path: '/foo', + hash: '#bar', + query: {}, + }) + }) + + it('extracts query and hash', () => { + expect(parseURL('/foo?a=one#bar')).toEqual({ + path: '/foo', + hash: '#bar', + query: { a: 'one' }, + }) + }) +}) diff --git a/jest.config.js b/jest.config.js index 09fdee67..adcdbe78 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,8 +1,9 @@ module.exports = { preset: 'ts-jest', testMatch: [ - '**/__tests__/**/*.spec.[jt]s?(x)', - '**/?(*.)+(spec|test).[jt]s?(x)', + '**/__tests__/**/*.spec.[j]s?(x)', + // '**/__tests__/**/*.spec.[jt]s?(x)', + // '**/?(*.)+(spec|test).[jt]s?(x)', ], testEnvironment: 'node', } diff --git a/package.json b/package.json index db9f69e3..382dcb8b 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "scripts": { "test:unit": "jest --coverage", "test:mocha": "mocha -r ts-node/register __tests__/**/*.spec.ts", + "test:mocha:js": "mocha -r ts-node/register __tests__/**/*.spec.js", "test:mocha:dev": "yarn run test:mocha -w --extension ts", "test:mocha:cov": "nyc -r lcov -e .ts -x \"*.spec.ts\" mocha -r ts-node/register __tests__/**/*.spec.ts && nyc report", "dev": "webpack-dev-server --mode=development" -- 2.47.3