From: Eduardo San Martin Morote Date: Mon, 3 May 2021 15:58:01 +0000 (+0200) Subject: test: add __TEST__ X-Git-Tag: v4.0.7~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c7d80bc6bff1e857ff55af4ff3a1c93ebaa1a56;p=thirdparty%2Fvuejs%2Frouter.git test: add __TEST__ --- diff --git a/jest.config.js b/jest.config.js index dfc9f3af..549933e2 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,6 +2,7 @@ module.exports = { testEnvironment: 'node', globals: { __DEV__: true, + __TEST__: true, __BROWSER__: true, }, coverageDirectory: 'coverage', diff --git a/rollup.config.js b/rollup.config.js index 2bb6b7ec..32fdf84c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -147,7 +147,7 @@ function createReplacePlugin( : // hard coded dev/prod builds JSON.stringify(!isProduction), // this is only used during tests - __TEST__: isBundlerESMBuild ? `(process.env.NODE_ENV === 'test')` : 'false', + __TEST__: 'false', // If the build is expected to run directly in the browser (global / esm builds) __BROWSER__: isBrowserBuild, __FEATURE_PROD_DEVTOOLS__: isBundlerESMBuild diff --git a/src/global.d.ts b/src/global.d.ts index e348e51e..bb649e5a 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,5 +1,6 @@ // Global compile-time constants declare var __DEV__: boolean +declare var __TEST__: boolean declare var __FEATURE_PROD_DEVTOOLS__: boolean declare var __BROWSER__: boolean declare var __CI__: boolean diff --git a/src/history/memory.ts b/src/history/memory.ts index 5a021fbb..5d3684f9 100644 --- a/src/history/memory.ts +++ b/src/history/memory.ts @@ -102,5 +102,17 @@ export function createMemoryHistory(base: string = ''): RouterHistory { get: () => queue[position], }) + if (__TEST__) { + // @ts-ignore: only for tests + routerHistory.changeURL = function (url: string) { + const from = this.location + queue.splice(position++ + 1, queue.length, url) + triggerListeners(this.location, from, { + direction: NavigationDirection.unknown, + delta: 0, + }) + } + } + return routerHistory }