From 3e9dab413f4eda8d6bce565388c5ddb7aeff9f7e Mon Sep 17 00:00:00 2001 From: Chance Strickland Date: Tue, 22 Feb 2022 13:38:15 -0800 Subject: [PATCH] chore: Format `dev` with Prettier defaults (#942) * chore: use default prettier config * chore: add format script and update prettier * chore: format with prettier --- .github/lock.yml | 1 - .prettierrc | 5 +- docs/api-reference.md | 12 +- docs/blocking-transitions.md | 2 +- docs/getting-started.md | 16 +- docs/installation.md | 10 +- docs/navigation.md | 19 +- package-lock.json | 14 +- package.json | 3 +- .../TestSequences/BackButtonTransitionHook.js | 18 +- .../TestSequences/BlockEverything.js | 12 +- .../TestSequences/BlockPopWithoutListening.js | 6 +- .../EncodedReservedCharacters.js | 20 +- .../history/__tests__/TestSequences/GoBack.js | 18 +- .../__tests__/TestSequences/GoForward.js | 22 +-- .../InitialLocationDefaultKey.js | 8 +- .../TestSequences/InitialLocationHasKey.js | 6 +- .../history/__tests__/TestSequences/Listen.js | 4 +- .../TestSequences/PushMissingPathname.js | 28 +-- .../TestSequences/PushNewLocation.js | 20 +- .../TestSequences/PushRelativePathname.js | 28 +-- .../PushRelativePathnameWarning.js | 30 +-- .../__tests__/TestSequences/PushSamePath.js | 24 +-- .../__tests__/TestSequences/PushState.js | 20 +- .../TestSequences/ReplaceNewLocation.js | 30 +-- .../TestSequences/ReplaceSamePath.js | 20 +- .../__tests__/TestSequences/ReplaceState.js | 20 +- .../history/__tests__/TestSequences/utils.js | 8 +- packages/history/__tests__/browser-test.js | 128 ++++++------- .../history/__tests__/create-path-test.js | 66 +++---- packages/history/__tests__/hash-base-test.js | 26 +-- packages/history/__tests__/hash-test.js | 126 ++++++------- packages/history/__tests__/memory-test.js | 150 +++++++-------- packages/history/browser.ts | 2 +- packages/history/hash.ts | 2 +- packages/history/index.ts | 138 +++++++------- packages/history/node-main.js | 6 +- scripts/build.js | 8 +- scripts/karma.conf.js | 102 +++++----- scripts/publish.js | 32 ++-- scripts/rollup/history.config.js | 178 +++++++++--------- scripts/test.js | 8 +- scripts/tests.webpack.js | 2 +- scripts/version.js | 32 ++-- 44 files changed, 714 insertions(+), 716 deletions(-) diff --git a/.github/lock.yml b/.github/lock.yml index df9daf80b..8497b4806 100644 --- a/.github/lock.yml +++ b/.github/lock.yml @@ -11,7 +11,6 @@ lockLabel: false # Comment to post before locking. Set to `false` to disable lockComment: false - # Limit to only `issues` or `pulls` # only: issues diff --git a/.prettierrc b/.prettierrc index 32ebab4e5..0967ef424 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,4 +1 @@ -{ - "singleQuote": true, - "trailingComma": "none" -} +{} diff --git a/docs/api-reference.md b/docs/api-reference.md index e56f94db1..99526db9c 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -119,7 +119,7 @@ A browser history object keeps track of the browsing history of an application u `createBrowserHistory` returns a `BrowserHistory` instance. `window` defaults to [the `defaultView` of the current `document`](https://developer.mozilla.org/en-US/docs/Web/API/Document/defaultView). ```ts -import { createBrowserHistory } from 'history'; +import { createBrowserHistory } from "history"; let history = createBrowserHistory(); ``` @@ -150,8 +150,8 @@ interface Path { The `createPath` and `parsePath` functions are useful for creating and parsing URL paths. ```ts -createPath({ pathname: '/login', search: '?next=home' }); // "/login?next=home" -parsePath('/login?next=home'); // { pathname: '/login', search: '?next=home' } +createPath({ pathname: "/login", search: "?next=home" }); // "/login?next=home" +parsePath("/login?next=home"); // { pathname: '/login', search: '?next=home' } ``` @@ -177,7 +177,7 @@ A hash history object keeps track of the browsing history of an application usin The main difference between this and [browser history](#createbrowserhistory) is that a hash history stores the current location in the [`hash` portion of the URL](https://developer.mozilla.org/en-US/docs/Web/API/Location/hash#:~:text=The%20hash%20property%20of%20the,an%20empty%20string%2C%20%22%22%20.), which means that it is not ever sent to the server. This can be useful if you are hosting your site on a domain where you do not have full control over the server routes, or e.g. in an Electron app where you don't want to configure the "server" to serve the same page at different URLs. ```ts -import { createHashHistory } from 'history'; +import { createHashHistory } from "history"; let history = createHashHistory(); ``` @@ -211,11 +211,11 @@ A memory history object keeps track of the browsing history of an application us `createMemoryHistory` returns a `MemoryHistory` instance. You can provide initial entries to this history instance through the `initialEntries` property, which defaults to `['/']` (a single location at the root `/` URL). The `initialIndex` defaults to the index of the last item in `initialEntries`. ```ts -import { createMemoryHistory } from 'history'; +import { createMemoryHistory } from "history"; let history = createMemoryHistory(); // Or, to pre-seed the history instance with some URLs: let history = createMemoryHistory({ - initialEntries: ['/home', '/profile', '/about'] + initialEntries: ["/home", "/profile", "/about"], }); ``` diff --git a/docs/blocking-transitions.md b/docs/blocking-transitions.md index 4ff278855..70a1df96d 100644 --- a/docs/blocking-transitions.md +++ b/docs/blocking-transitions.md @@ -8,7 +8,7 @@ they will lose some unsaved changes they've made. ```js // Block navigation and register a callback that // fires when a navigation attempt is blocked. -let unblock = history.block(tx => { +let unblock = history.block((tx) => { // Navigation was blocked! Let's show a confirmation dialog // so the user can decide if they actually want to navigate // away and discard changes they've made in the current page. diff --git a/docs/getting-started.md b/docs/getting-started.md index d4512873d..0bca31ce0 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -23,11 +23,11 @@ Basic usage looks like this: ```js // Create your own history instance. -import { createBrowserHistory } from 'history'; +import { createBrowserHistory } from "history"; let history = createBrowserHistory(); // ... or just import the browser history singleton instance. -import history from 'history/browser'; +import history from "history/browser"; // Alternatively, if you're using hash history import // the hash history singleton instance. @@ -42,10 +42,10 @@ let unlisten = history.listen(({ location, action }) => { }); // Use push to push a new entry onto the history stack. -history.push('/home', { some: 'state' }); +history.push("/home", { some: "state" }); // Use replace to replace the current entry in the stack. -history.replace('/logged-in'); +history.replace("/logged-in"); // Use back/forward to navigate one entry back or forward. history.back(); @@ -58,7 +58,7 @@ If you're using memory history you'll need to create your own `history` object before you can use it. ```js -import { createMemoryHistory } from 'history'; +import { createMemoryHistory } from "history"; let history = createMemoryHistory(); ``` @@ -67,9 +67,9 @@ current `document` (like an iframe), you'll need to create your own browser/hash history: ```js -import { createBrowserHistory } from 'history'; +import { createBrowserHistory } from "history"; let history = createBrowserHistory({ - window: iframe.contentWindow + window: iframe.contentWindow, }); ``` @@ -134,7 +134,7 @@ unlisten(); The main history bundle also contains both `createPath` and `parsePath` methods that may be useful when working with URL paths. ```js -let pathPieces = parsePath('/the/path?the=query#the-hash'); +let pathPieces = parsePath("/the/path?the=query#the-hash"); // pathPieces = { // pathname: '/the/path', // search: '?the=query', diff --git a/docs/installation.md b/docs/installation.md index 84c67d47c..46946e86a 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -14,7 +14,7 @@ versions of Webpack and Parcel are also good choices. Then you can write your code using JavaScript `import` statements, like this: ```js -import { createBrowserHistory } from 'history'; +import { createBrowserHistory } from "history"; // ... ``` @@ -22,7 +22,7 @@ If you're using a bundler that doesn't understand JavaScript modules and only understands CommonJS, you can use `require` as you would with anything else: ```js -var createBrowserHistory = require('history').createBrowserHistory; +var createBrowserHistory = require("history").createBrowserHistory; ``` ## Using ` ``` diff --git a/docs/navigation.md b/docs/navigation.md index cfe3b8a39..6c91e2bc2 100644 --- a/docs/navigation.md +++ b/docs/navigation.md @@ -13,20 +13,23 @@ An example: ```js // Push a new entry onto the history stack. -history.push('/home'); +history.push("/home"); // Push a new entry onto the history stack with a query string // and some state. Location state does not appear in the URL. -history.push('/home?the=query', { some: 'state' }); +history.push("/home?the=query", { some: "state" }); // If you prefer, use a location-like object to specify the URL. // This is equivalent to the example above. -history.push({ - pathname: '/home', - search: '?the=query' -}, { - some: state -}); +history.push( + { + pathname: "/home", + search: "?the=query", + }, + { + some: state, + } +); // Go back to the previous history entry. The following // two lines are synonymous. diff --git a/package-lock.json b/package-lock.json index ea816914b..8e35e20ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,7 +41,7 @@ "karma-sourcemap-loader": "0.3.8", "karma-webpack": "^3.0.5", "mocha": "^5.2.0", - "prettier": "^2.3.2", + "prettier": "^2.5.1", "prompt-confirm": "^2.0.4", "rollup": "^2.56.2", "rollup-plugin-copy": "^3.4.0", @@ -8687,9 +8687,9 @@ } }, "node_modules/prettier": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.2.tgz", - "integrity": "sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==", + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.5.1.tgz", + "integrity": "sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==", "bin": { "prettier": "bin-prettier.js" }, @@ -18927,9 +18927,9 @@ "integrity": "sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=" }, "prettier": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.2.tgz", - "integrity": "sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==" + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.5.1.tgz", + "integrity": "sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==" }, "pretty-format": { "version": "21.2.1", diff --git a/package.json b/package.json index 19ba6aab0..4f61635a4 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "build": "node ./scripts/build.js", "clean": "git clean -fdX .", "lint": "eslint .", + "format": "prettier --ignore-path .eslintignore --write .", "publish": "node ./scripts/publish.js", "size": "filesize", "test": "node ./scripts/test.js", @@ -47,7 +48,7 @@ "karma-sourcemap-loader": "0.3.8", "karma-webpack": "^3.0.5", "mocha": "^5.2.0", - "prettier": "^2.3.2", + "prettier": "^2.5.1", "prompt-confirm": "^2.0.4", "rollup": "^2.56.2", "rollup-plugin-copy": "^3.4.0", diff --git a/packages/history/__tests__/TestSequences/BackButtonTransitionHook.js b/packages/history/__tests__/TestSequences/BackButtonTransitionHook.js index 56f773a8f..4d7c16c37 100644 --- a/packages/history/__tests__/TestSequences/BackButtonTransitionHook.js +++ b/packages/history/__tests__/TestSequences/BackButtonTransitionHook.js @@ -1,6 +1,6 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let hookWasCalled = false; @@ -9,15 +9,15 @@ export default (history, done) => { let steps = [ ({ location }) => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); - history.push('/home'); + history.push("/home"); }, ({ action, location }) => { - expect(action).toBe('PUSH'); + expect(action).toBe("PUSH"); expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home", }); unblock = history.block(() => { @@ -27,15 +27,15 @@ export default (history, done) => { window.history.go(-1); }, ({ action, location }) => { - expect(action).toBe('POP'); + expect(action).toBe("POP"); expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); expect(hookWasCalled).toBe(true); unblock(); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/BlockEverything.js b/packages/history/__tests__/TestSequences/BlockEverything.js index 67fbdf879..8b54c195d 100644 --- a/packages/history/__tests__/TestSequences/BlockEverything.js +++ b/packages/history/__tests__/TestSequences/BlockEverything.js @@ -1,24 +1,24 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let steps = [ ({ location }) => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); let unblock = history.block(); - history.push('/home'); + history.push("/home"); expect(history.location).toMatchObject({ - pathname: '/' + pathname: "/", }); unblock(); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/BlockPopWithoutListening.js b/packages/history/__tests__/TestSequences/BlockPopWithoutListening.js index 3925870e8..de44906a4 100644 --- a/packages/history/__tests__/TestSequences/BlockPopWithoutListening.js +++ b/packages/history/__tests__/TestSequences/BlockPopWithoutListening.js @@ -1,11 +1,11 @@ -import expect from 'expect'; +import expect from "expect"; export default (history, done) => { expect(history.location).toMatchObject({ - pathname: '/' + pathname: "/", }); - history.push('/home'); + history.push("/home"); let transitionHookWasCalled = false; let unblock = history.block(() => { diff --git a/packages/history/__tests__/TestSequences/EncodedReservedCharacters.js b/packages/history/__tests__/TestSequences/EncodedReservedCharacters.js index bdb75843e..8b7f55dee 100644 --- a/packages/history/__tests__/TestSequences/EncodedReservedCharacters.js +++ b/packages/history/__tests__/TestSequences/EncodedReservedCharacters.js @@ -1,36 +1,36 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let steps = [ () => { // encoded string - let pathname = '/view/%23abc'; + let pathname = "/view/%23abc"; history.replace(pathname); }, ({ location }) => { expect(location).toMatchObject({ - pathname: '/view/%23abc' + pathname: "/view/%23abc", }); // encoded object - let pathname = '/view/%23abc'; + let pathname = "/view/%23abc"; history.replace({ pathname }); }, ({ location }) => { expect(location).toMatchObject({ - pathname: '/view/%23abc' + pathname: "/view/%23abc", }); // unencoded string - let pathname = '/view/#abc'; + let pathname = "/view/#abc"; history.replace(pathname); }, ({ location }) => { expect(location).toMatchObject({ - pathname: '/view/', - hash: '#abc' + pathname: "/view/", + hash: "#abc", }); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/GoBack.js b/packages/history/__tests__/TestSequences/GoBack.js index 09c2d030c..8e65c3abc 100644 --- a/packages/history/__tests__/TestSequences/GoBack.js +++ b/packages/history/__tests__/TestSequences/GoBack.js @@ -1,30 +1,30 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let steps = [ ({ location }) => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); - history.push('/home'); + history.push("/home"); }, ({ action, location }) => { - expect(action).toEqual('PUSH'); + expect(action).toEqual("PUSH"); expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home", }); history.back(); }, ({ action, location }) => { - expect(action).toEqual('POP'); + expect(action).toEqual("POP"); expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/GoForward.js b/packages/history/__tests__/TestSequences/GoForward.js index 0e6c86513..9f6971eeb 100644 --- a/packages/history/__tests__/TestSequences/GoForward.js +++ b/packages/history/__tests__/TestSequences/GoForward.js @@ -1,38 +1,38 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let steps = [ ({ location }) => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); - history.push('/home'); + history.push("/home"); }, ({ action, location }) => { - expect(action).toEqual('PUSH'); + expect(action).toEqual("PUSH"); expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home", }); history.back(); }, ({ action, location }) => { - expect(action).toEqual('POP'); + expect(action).toEqual("POP"); expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); history.forward(); }, ({ action, location }) => { - expect(action).toEqual('POP'); + expect(action).toEqual("POP"); expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home", }); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/InitialLocationDefaultKey.js b/packages/history/__tests__/TestSequences/InitialLocationDefaultKey.js index 1ca263398..45294b6b0 100644 --- a/packages/history/__tests__/TestSequences/InitialLocationDefaultKey.js +++ b/packages/history/__tests__/TestSequences/InitialLocationDefaultKey.js @@ -1,12 +1,12 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let steps = [ ({ location }) => { - expect(location.key).toBe('default'); - } + expect(location.key).toBe("default"); + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/InitialLocationHasKey.js b/packages/history/__tests__/TestSequences/InitialLocationHasKey.js index a932fcc46..76fc4b5dd 100644 --- a/packages/history/__tests__/TestSequences/InitialLocationHasKey.js +++ b/packages/history/__tests__/TestSequences/InitialLocationHasKey.js @@ -1,12 +1,12 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let steps = [ ({ location }) => { expect(location.key).toBeTruthy(); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/Listen.js b/packages/history/__tests__/TestSequences/Listen.js index b27502fbc..75a895e58 100644 --- a/packages/history/__tests__/TestSequences/Listen.js +++ b/packages/history/__tests__/TestSequences/Listen.js @@ -1,5 +1,5 @@ -import expect from 'expect'; -import mock from 'jest-mock'; +import expect from "expect"; +import mock from "jest-mock"; export default (history, done) => { let spy = mock.fn(); diff --git a/packages/history/__tests__/TestSequences/PushMissingPathname.js b/packages/history/__tests__/TestSequences/PushMissingPathname.js index 57366b30a..ef3b8e371 100644 --- a/packages/history/__tests__/TestSequences/PushMissingPathname.js +++ b/packages/history/__tests__/TestSequences/PushMissingPathname.js @@ -1,34 +1,34 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let steps = [ ({ location }) => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); - history.push('/home?the=query#the-hash'); + history.push("/home?the=query#the-hash"); }, ({ action, location }) => { - expect(action).toBe('PUSH'); + expect(action).toBe("PUSH"); expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash' + pathname: "/home", + search: "?the=query", + hash: "#the-hash", }); - history.push('?another=query#another-hash'); + history.push("?another=query#another-hash"); }, ({ action, location }) => { - expect(action).toBe('PUSH'); + expect(action).toBe("PUSH"); expect(location).toMatchObject({ - pathname: '/home', - search: '?another=query', - hash: '#another-hash' + pathname: "/home", + search: "?another=query", + hash: "#another-hash", }); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/PushNewLocation.js b/packages/history/__tests__/TestSequences/PushNewLocation.js index 5624f7054..cc4516723 100644 --- a/packages/history/__tests__/TestSequences/PushNewLocation.js +++ b/packages/history/__tests__/TestSequences/PushNewLocation.js @@ -1,26 +1,26 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let steps = [ ({ location }) => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); - history.push('/home?the=query#the-hash'); + history.push("/home?the=query#the-hash"); }, ({ action, location }) => { - expect(action).toBe('PUSH'); + expect(action).toBe("PUSH"); expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash', + pathname: "/home", + search: "?the=query", + hash: "#the-hash", state: null, - key: expect.any(String) + key: expect.any(String), }); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/PushRelativePathname.js b/packages/history/__tests__/TestSequences/PushRelativePathname.js index a76223ec2..14684713a 100644 --- a/packages/history/__tests__/TestSequences/PushRelativePathname.js +++ b/packages/history/__tests__/TestSequences/PushRelativePathname.js @@ -1,34 +1,34 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let steps = [ ({ location }) => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); - history.push('/the/path?the=query#the-hash'); + history.push("/the/path?the=query#the-hash"); }, ({ action, location }) => { - expect(action).toBe('PUSH'); + expect(action).toBe("PUSH"); expect(location).toMatchObject({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash", }); - history.push('../other/path?another=query#another-hash'); + history.push("../other/path?another=query#another-hash"); }, ({ action, location }) => { - expect(action).toBe('PUSH'); + expect(action).toBe("PUSH"); expect(location).toMatchObject({ - pathname: '/other/path', - search: '?another=query', - hash: '#another-hash' + pathname: "/other/path", + search: "?another=query", + hash: "#another-hash", }); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/PushRelativePathnameWarning.js b/packages/history/__tests__/TestSequences/PushRelativePathnameWarning.js index 85cb9bc29..65b27b25f 100644 --- a/packages/history/__tests__/TestSequences/PushRelativePathnameWarning.js +++ b/packages/history/__tests__/TestSequences/PushRelativePathnameWarning.js @@ -1,41 +1,41 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps, spyOn } from './utils.js'; +import { execSteps, spyOn } from "./utils.js"; export default (history, done) => { let steps = [ ({ location }) => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); - history.push('/the/path?the=query#the-hash'); + history.push("/the/path?the=query#the-hash"); }, ({ action, location }) => { - expect(action).toBe('PUSH'); + expect(action).toBe("PUSH"); expect(location).toMatchObject({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash", }); - let { spy, destroy } = spyOn(console, 'warn'); + let { spy, destroy } = spyOn(console, "warn"); - history.push('../other/path?another=query#another-hash'); + history.push("../other/path?another=query#another-hash"); expect(spy).toHaveBeenCalledWith( - expect.stringContaining('relative pathnames are not supported') + expect.stringContaining("relative pathnames are not supported") ); destroy(); }, ({ location }) => { expect(location).toMatchObject({ - pathname: '../other/path', - search: '?another=query', - hash: '#another-hash' + pathname: "../other/path", + search: "?another=query", + hash: "#another-hash", }); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/PushSamePath.js b/packages/history/__tests__/TestSequences/PushSamePath.js index 67fcceead..3dc705f87 100644 --- a/packages/history/__tests__/TestSequences/PushSamePath.js +++ b/packages/history/__tests__/TestSequences/PushSamePath.js @@ -1,38 +1,38 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let steps = [ ({ location }) => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); - history.push('/home'); + history.push("/home"); }, ({ action, location }) => { - expect(action).toBe('PUSH'); + expect(action).toBe("PUSH"); expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home", }); - history.push('/home'); + history.push("/home"); }, ({ action, location }) => { - expect(action).toBe('PUSH'); + expect(action).toBe("PUSH"); expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home", }); history.back(); }, ({ action, location }) => { - expect(action).toBe('POP'); + expect(action).toBe("POP"); expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home", }); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/PushState.js b/packages/history/__tests__/TestSequences/PushState.js index 65b86a67b..36d462c2d 100644 --- a/packages/history/__tests__/TestSequences/PushState.js +++ b/packages/history/__tests__/TestSequences/PushState.js @@ -1,25 +1,25 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let steps = [ ({ location }) => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); - history.push('/home?the=query#the-hash', { the: 'state' }); + history.push("/home?the=query#the-hash", { the: "state" }); }, ({ action, location }) => { - expect(action).toBe('PUSH'); + expect(action).toBe("PUSH"); expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash', - state: { the: 'state' } + pathname: "/home", + search: "?the=query", + hash: "#the-hash", + state: { the: "state" }, }); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/ReplaceNewLocation.js b/packages/history/__tests__/TestSequences/ReplaceNewLocation.js index 1522858fc..0f8e86536 100644 --- a/packages/history/__tests__/TestSequences/ReplaceNewLocation.js +++ b/packages/history/__tests__/TestSequences/ReplaceNewLocation.js @@ -1,37 +1,37 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let steps = [ ({ location }) => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); - history.replace('/home?the=query#the-hash'); + history.replace("/home?the=query#the-hash"); }, ({ action, location }) => { - expect(action).toBe('REPLACE'); + expect(action).toBe("REPLACE"); expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash', + pathname: "/home", + search: "?the=query", + hash: "#the-hash", state: null, - key: expect.any(String) + key: expect.any(String), }); - history.replace('/'); + history.replace("/"); }, ({ action, location }) => { - expect(action).toBe('REPLACE'); + expect(action).toBe("REPLACE"); expect(location).toMatchObject({ - pathname: '/', - search: '', + pathname: "/", + search: "", state: null, - key: expect.any(String) + key: expect.any(String), }); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/ReplaceSamePath.js b/packages/history/__tests__/TestSequences/ReplaceSamePath.js index ca1b059bb..7d8c46a29 100644 --- a/packages/history/__tests__/TestSequences/ReplaceSamePath.js +++ b/packages/history/__tests__/TestSequences/ReplaceSamePath.js @@ -1,6 +1,6 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let prevLocation; @@ -8,29 +8,29 @@ export default (history, done) => { let steps = [ ({ location }) => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); - history.replace('/home'); + history.replace("/home"); }, ({ action, location }) => { - expect(action).toBe('REPLACE'); + expect(action).toBe("REPLACE"); expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home", }); prevLocation = location; - history.replace('/home'); + history.replace("/home"); }, ({ action, location }) => { - expect(action).toBe('REPLACE'); + expect(action).toBe("REPLACE"); expect(location).toMatchObject({ - pathname: '/home' + pathname: "/home", }); expect(location).not.toBe(prevLocation); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/ReplaceState.js b/packages/history/__tests__/TestSequences/ReplaceState.js index 73214596f..f8fbc2289 100644 --- a/packages/history/__tests__/TestSequences/ReplaceState.js +++ b/packages/history/__tests__/TestSequences/ReplaceState.js @@ -1,25 +1,25 @@ -import expect from 'expect'; +import expect from "expect"; -import { execSteps } from './utils.js'; +import { execSteps } from "./utils.js"; export default (history, done) => { let steps = [ ({ location }) => { expect(location).toMatchObject({ - pathname: '/' + pathname: "/", }); - history.replace('/home?the=query#the-hash', { the: 'state' }); + history.replace("/home?the=query#the-hash", { the: "state" }); }, ({ action, location }) => { - expect(action).toBe('REPLACE'); + expect(action).toBe("REPLACE"); expect(location).toMatchObject({ - pathname: '/home', - search: '?the=query', - hash: '#the-hash', - state: { the: 'state' } + pathname: "/home", + search: "?the=query", + hash: "#the-hash", + state: { the: "state" }, }); - } + }, ]; execSteps(steps, history, done); diff --git a/packages/history/__tests__/TestSequences/utils.js b/packages/history/__tests__/TestSequences/utils.js index bb384bc3b..94ddaa1ef 100644 --- a/packages/history/__tests__/TestSequences/utils.js +++ b/packages/history/__tests__/TestSequences/utils.js @@ -1,4 +1,4 @@ -import mock from 'jest-mock'; +import mock from "jest-mock"; export function spyOn(object, method) { let original = object[method]; @@ -10,7 +10,7 @@ export function spyOn(object, method) { spy, destroy() { object[method] = original; - } + }, }; } @@ -30,7 +30,7 @@ export function execSteps(steps, history, done) { function execNextStep(...args) { try { let nextStep = steps[index++]; - if (!nextStep) throw new Error('Test is missing step ' + index); + if (!nextStep) throw new Error("Test is missing step " + index); nextStep(...args); @@ -45,7 +45,7 @@ export function execSteps(steps, history, done) { execNextStep({ action: history.action, - location: history.location + location: history.location, }); } else { done(); diff --git a/packages/history/__tests__/browser-test.js b/packages/history/__tests__/browser-test.js index a164bdeb1..983b9a8c4 100644 --- a/packages/history/__tests__/browser-test.js +++ b/packages/history/__tests__/browser-test.js @@ -1,142 +1,142 @@ -import expect from 'expect'; -import { createBrowserHistory } from 'history'; - -import InitialLocationDefaultKey from './TestSequences/InitialLocationDefaultKey.js'; -import Listen from './TestSequences/Listen.js'; -import PushNewLocation from './TestSequences/PushNewLocation.js'; -import PushSamePath from './TestSequences/PushSamePath.js'; -import PushState from './TestSequences/PushState.js'; -import PushMissingPathname from './TestSequences/PushMissingPathname.js'; -import PushRelativePathname from './TestSequences/PushRelativePathname.js'; -import ReplaceNewLocation from './TestSequences/ReplaceNewLocation.js'; -import ReplaceSamePath from './TestSequences/ReplaceSamePath.js'; -import ReplaceState from './TestSequences/ReplaceState.js'; -import EncodedReservedCharacters from './TestSequences/EncodedReservedCharacters.js'; -import GoBack from './TestSequences/GoBack.js'; -import GoForward from './TestSequences/GoForward.js'; -import BlockEverything from './TestSequences/BlockEverything.js'; -import BlockPopWithoutListening from './TestSequences/BlockPopWithoutListening.js'; - -describe('a browser history', () => { +import expect from "expect"; +import { createBrowserHistory } from "history"; + +import InitialLocationDefaultKey from "./TestSequences/InitialLocationDefaultKey.js"; +import Listen from "./TestSequences/Listen.js"; +import PushNewLocation from "./TestSequences/PushNewLocation.js"; +import PushSamePath from "./TestSequences/PushSamePath.js"; +import PushState from "./TestSequences/PushState.js"; +import PushMissingPathname from "./TestSequences/PushMissingPathname.js"; +import PushRelativePathname from "./TestSequences/PushRelativePathname.js"; +import ReplaceNewLocation from "./TestSequences/ReplaceNewLocation.js"; +import ReplaceSamePath from "./TestSequences/ReplaceSamePath.js"; +import ReplaceState from "./TestSequences/ReplaceState.js"; +import EncodedReservedCharacters from "./TestSequences/EncodedReservedCharacters.js"; +import GoBack from "./TestSequences/GoBack.js"; +import GoForward from "./TestSequences/GoForward.js"; +import BlockEverything from "./TestSequences/BlockEverything.js"; +import BlockPopWithoutListening from "./TestSequences/BlockPopWithoutListening.js"; + +describe("a browser history", () => { let history; beforeEach(() => { - window.history.replaceState(null, null, '/'); + window.history.replaceState(null, null, "/"); history = createBrowserHistory(); }); - it('knows how to create hrefs from location objects', () => { + it("knows how to create hrefs from location objects", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash", }); - expect(href).toEqual('/the/path?the=query#the-hash'); + expect(href).toEqual("/the/path?the=query#the-hash"); }); - it('knows how to create hrefs from strings', () => { - const href = history.createHref('/the/path?the=query#the-hash'); - expect(href).toEqual('/the/path?the=query#the-hash'); + it("knows how to create hrefs from strings", () => { + const href = history.createHref("/the/path?the=query#the-hash"); + expect(href).toEqual("/the/path?the=query#the-hash"); }); - it('does not encode the generated path', () => { + it("does not encode the generated path", () => { const encodedHref = history.createHref({ - pathname: '/%23abc' + pathname: "/%23abc", }); - expect(encodedHref).toEqual('/%23abc'); + expect(encodedHref).toEqual("/%23abc"); const unencodedHref = history.createHref({ - pathname: '/#abc' + pathname: "/#abc", }); - expect(unencodedHref).toEqual('/#abc'); + expect(unencodedHref).toEqual("/#abc"); }); - describe('listen', () => { - it('does not immediately call listeners', done => { + describe("listen", () => { + it("does not immediately call listeners", (done) => { Listen(history, done); }); }); - describe('the initial location', () => { - it('has the "default" key', done => { + describe("the initial location", () => { + it('has the "default" key', (done) => { InitialLocationDefaultKey(history, done); }); }); - describe('push a new path', () => { - it('calls change listeners with the new location', done => { + describe("push a new path", () => { + it("calls change listeners with the new location", (done) => { PushNewLocation(history, done); }); }); - describe('push the same path', () => { - it('calls change listeners with the new location', done => { + describe("push the same path", () => { + it("calls change listeners with the new location", (done) => { PushSamePath(history, done); }); }); - describe('push state', () => { - it('calls change listeners with the new location', done => { + describe("push state", () => { + it("calls change listeners with the new location", (done) => { PushState(history, done); }); }); - describe('push with no pathname', () => { - it('reuses the current location pathname', done => { + describe("push with no pathname", () => { + it("reuses the current location pathname", (done) => { PushMissingPathname(history, done); }); }); - describe('push with a relative pathname', () => { - it('normalizes the pathname relative to the current location', done => { + describe("push with a relative pathname", () => { + it("normalizes the pathname relative to the current location", (done) => { PushRelativePathname(history, done); }); }); - describe('replace a new path', () => { - it('calls change listeners with the new location', done => { + describe("replace a new path", () => { + it("calls change listeners with the new location", (done) => { ReplaceNewLocation(history, done); }); }); - describe('replace the same path', () => { - it('calls change listeners with the new location', done => { + describe("replace the same path", () => { + it("calls change listeners with the new location", (done) => { ReplaceSamePath(history, done); }); }); - describe('replace state', () => { - it('calls change listeners with the new location', done => { + describe("replace state", () => { + it("calls change listeners with the new location", (done) => { ReplaceState(history, done); }); }); - describe('location created with encoded/unencoded reserved characters', () => { - it('produces different location objects', done => { + describe("location created with encoded/unencoded reserved characters", () => { + it("produces different location objects", (done) => { EncodedReservedCharacters(history, done); }); }); - describe('back', () => { - it('calls change listeners with the previous location', done => { + describe("back", () => { + it("calls change listeners with the previous location", (done) => { GoBack(history, done); }); }); - describe('forward', () => { - it('calls change listeners with the next location', done => { + describe("forward", () => { + it("calls change listeners with the next location", (done) => { GoForward(history, done); }); }); - describe('block', () => { - it('blocks all transitions', done => { + describe("block", () => { + it("blocks all transitions", (done) => { BlockEverything(history, done); }); }); - describe('block a POP without listening', () => { - it('receives the next ({ action, location })', done => { + describe("block a POP without listening", () => { + it("receives the next ({ action, location })", (done) => { BlockPopWithoutListening(history, done); }); }); diff --git a/packages/history/__tests__/create-path-test.js b/packages/history/__tests__/create-path-test.js index 236e8afad..b562c3a1a 100644 --- a/packages/history/__tests__/create-path-test.js +++ b/packages/history/__tests__/create-path-test.js @@ -1,62 +1,62 @@ -import expect from 'expect'; -import { createPath } from 'history'; +import expect from "expect"; +import { createPath } from "history"; -describe('createPath', () => { - describe('given only a pathname', () => { - it('returns the pathname unchanged', () => { - let path = createPath({ pathname: 'https://google.com' }); - expect(path).toBe('https://google.com'); +describe("createPath", () => { + describe("given only a pathname", () => { + it("returns the pathname unchanged", () => { + let path = createPath({ pathname: "https://google.com" }); + expect(path).toBe("https://google.com"); }); }); - describe('given a pathname and a search param', () => { - it('returns the constructed pathname', () => { + describe("given a pathname and a search param", () => { + it("returns the constructed pathname", () => { let path = createPath({ - pathname: 'https://google.com', - search: '?something=cool' + pathname: "https://google.com", + search: "?something=cool", }); - expect(path).toBe('https://google.com?something=cool'); + expect(path).toBe("https://google.com?something=cool"); }); }); - describe('given a pathname and a search param without ?', () => { - it('returns the constructed pathname', () => { + describe("given a pathname and a search param without ?", () => { + it("returns the constructed pathname", () => { let path = createPath({ - pathname: 'https://google.com', - search: 'something=cool' + pathname: "https://google.com", + search: "something=cool", }); - expect(path).toBe('https://google.com?something=cool'); + expect(path).toBe("https://google.com?something=cool"); }); }); - describe('given a pathname and a hash param', () => { - it('returns the constructed pathname', () => { + describe("given a pathname and a hash param", () => { + it("returns the constructed pathname", () => { let path = createPath({ - pathname: 'https://google.com', - hash: '#section-1' + pathname: "https://google.com", + hash: "#section-1", }); - expect(path).toBe('https://google.com#section-1'); + expect(path).toBe("https://google.com#section-1"); }); }); - describe('given a pathname and a hash param without #', () => { - it('returns the constructed pathname', () => { + describe("given a pathname and a hash param without #", () => { + it("returns the constructed pathname", () => { let path = createPath({ - pathname: 'https://google.com', - hash: 'section-1' + pathname: "https://google.com", + hash: "section-1", }); - expect(path).toBe('https://google.com#section-1'); + expect(path).toBe("https://google.com#section-1"); }); }); - describe('given a full location object', () => { - it('returns the constructed pathname', () => { + describe("given a full location object", () => { + it("returns the constructed pathname", () => { let path = createPath({ - pathname: 'https://google.com', - search: 'something=cool', - hash: '#section-1' + pathname: "https://google.com", + search: "something=cool", + hash: "#section-1", }); - expect(path).toBe('https://google.com?something=cool#section-1'); + expect(path).toBe("https://google.com?something=cool#section-1"); }); }); }); diff --git a/packages/history/__tests__/hash-base-test.js b/packages/history/__tests__/hash-base-test.js index dbbfa3ac0..523ce7957 100644 --- a/packages/history/__tests__/hash-base-test.js +++ b/packages/history/__tests__/hash-base-test.js @@ -1,15 +1,15 @@ -import expect from 'expect'; -import { createHashHistory } from 'history'; +import expect from "expect"; +import { createHashHistory } from "history"; -describe('a hash history on a page with a tag', () => { +describe("a hash history on a page with a tag", () => { let history, base; beforeEach(() => { - if (window.location.hash !== '#/') { - window.location.hash = '/'; + if (window.location.hash !== "#/") { + window.location.hash = "/"; } - base = document.createElement('base'); - base.setAttribute('href', '/prefix'); + base = document.createElement("base"); + base.setAttribute("href", "/prefix"); document.head.appendChild(base); @@ -20,19 +20,19 @@ describe('a hash history on a page with a tag', () => { document.head.removeChild(base); }); - it('knows how to create hrefs', () => { - const hashIndex = window.location.href.indexOf('#'); + it("knows how to create hrefs", () => { + const hashIndex = window.location.href.indexOf("#"); const upToHash = hashIndex === -1 ? window.location.href : window.location.href.slice(0, hashIndex); const href = history.createHref({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash", }); - expect(href).toEqual(upToHash + '#/the/path?the=query#the-hash'); + expect(href).toEqual(upToHash + "#/the/path?the=query#the-hash"); }); }); diff --git a/packages/history/__tests__/hash-test.js b/packages/history/__tests__/hash-test.js index b528893e4..ce74f87b6 100644 --- a/packages/history/__tests__/hash-test.js +++ b/packages/history/__tests__/hash-test.js @@ -1,146 +1,146 @@ -import expect from 'expect'; -import { createHashHistory } from 'history'; - -import Listen from './TestSequences/Listen.js'; -import InitialLocationDefaultKey from './TestSequences/InitialLocationDefaultKey.js'; -import PushNewLocation from './TestSequences/PushNewLocation.js'; -import PushSamePath from './TestSequences/PushSamePath.js'; -import PushState from './TestSequences/PushState.js'; -import PushMissingPathname from './TestSequences/PushMissingPathname.js'; -import PushRelativePathnameWarning from './TestSequences/PushRelativePathnameWarning.js'; -import ReplaceNewLocation from './TestSequences/ReplaceNewLocation.js'; -import ReplaceSamePath from './TestSequences/ReplaceSamePath.js'; -import ReplaceState from './TestSequences/ReplaceState.js'; -import EncodedReservedCharacters from './TestSequences/EncodedReservedCharacters.js'; -import GoBack from './TestSequences/GoBack.js'; -import GoForward from './TestSequences/GoForward.js'; -import BlockEverything from './TestSequences/BlockEverything.js'; -import BlockPopWithoutListening from './TestSequences/BlockPopWithoutListening.js'; +import expect from "expect"; +import { createHashHistory } from "history"; + +import Listen from "./TestSequences/Listen.js"; +import InitialLocationDefaultKey from "./TestSequences/InitialLocationDefaultKey.js"; +import PushNewLocation from "./TestSequences/PushNewLocation.js"; +import PushSamePath from "./TestSequences/PushSamePath.js"; +import PushState from "./TestSequences/PushState.js"; +import PushMissingPathname from "./TestSequences/PushMissingPathname.js"; +import PushRelativePathnameWarning from "./TestSequences/PushRelativePathnameWarning.js"; +import ReplaceNewLocation from "./TestSequences/ReplaceNewLocation.js"; +import ReplaceSamePath from "./TestSequences/ReplaceSamePath.js"; +import ReplaceState from "./TestSequences/ReplaceState.js"; +import EncodedReservedCharacters from "./TestSequences/EncodedReservedCharacters.js"; +import GoBack from "./TestSequences/GoBack.js"; +import GoForward from "./TestSequences/GoForward.js"; +import BlockEverything from "./TestSequences/BlockEverything.js"; +import BlockPopWithoutListening from "./TestSequences/BlockPopWithoutListening.js"; // TODO: Do we still need this? // const canGoWithoutReload = window.navigator.userAgent.indexOf('Firefox') === -1; // const describeGo = canGoWithoutReload ? describe : describe.skip; -describe('a hash history', () => { +describe("a hash history", () => { let history; beforeEach(() => { - window.history.replaceState(null, null, '#/'); + window.history.replaceState(null, null, "#/"); history = createHashHistory(); }); - it('knows how to create hrefs from location objects', () => { + it("knows how to create hrefs from location objects", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash", }); - expect(href).toEqual('#/the/path?the=query#the-hash'); + expect(href).toEqual("#/the/path?the=query#the-hash"); }); - it('knows how to create hrefs from strings', () => { - const href = history.createHref('/the/path?the=query#the-hash'); - expect(href).toEqual('#/the/path?the=query#the-hash'); + it("knows how to create hrefs from strings", () => { + const href = history.createHref("/the/path?the=query#the-hash"); + expect(href).toEqual("#/the/path?the=query#the-hash"); }); - it('does not encode the generated path', () => { + it("does not encode the generated path", () => { const encodedHref = history.createHref({ - pathname: '/%23abc' + pathname: "/%23abc", }); - expect(encodedHref).toEqual('#/%23abc'); + expect(encodedHref).toEqual("#/%23abc"); const unencodedHref = history.createHref({ - pathname: '/#abc' + pathname: "/#abc", }); - expect(unencodedHref).toEqual('#/#abc'); + expect(unencodedHref).toEqual("#/#abc"); }); - describe('listen', () => { - it('does not immediately call listeners', done => { + describe("listen", () => { + it("does not immediately call listeners", (done) => { Listen(history, done); }); }); - describe('the initial location', () => { - it('has the "default" key', done => { + describe("the initial location", () => { + it('has the "default" key', (done) => { InitialLocationDefaultKey(history, done); }); }); - describe('push a new path', () => { - it('calls change listeners with the new location', done => { + describe("push a new path", () => { + it("calls change listeners with the new location", (done) => { PushNewLocation(history, done); }); }); - describe('push the same path', () => { - it('calls change listeners with the new location', done => { + describe("push the same path", () => { + it("calls change listeners with the new location", (done) => { PushSamePath(history, done); }); }); - describe('push state', () => { - it('calls change listeners with the new location', done => { + describe("push state", () => { + it("calls change listeners with the new location", (done) => { PushState(history, done); }); }); - describe('push with no pathname', () => { - it('reuses the current location pathname', done => { + describe("push with no pathname", () => { + it("reuses the current location pathname", (done) => { PushMissingPathname(history, done); }); }); - describe('push with a relative pathname', () => { - it('issues a warning', done => { + describe("push with a relative pathname", () => { + it("issues a warning", (done) => { PushRelativePathnameWarning(history, done); }); }); - describe('replace a new path', () => { - it('calls change listeners with the new location', done => { + describe("replace a new path", () => { + it("calls change listeners with the new location", (done) => { ReplaceNewLocation(history, done); }); }); - describe('replace the same path', () => { - it('calls change listeners with the new location', done => { + describe("replace the same path", () => { + it("calls change listeners with the new location", (done) => { ReplaceSamePath(history, done); }); }); - describe('replace state', () => { - it('calls change listeners with the new location', done => { + describe("replace state", () => { + it("calls change listeners with the new location", (done) => { ReplaceState(history, done); }); }); - describe('location created with encoded/unencoded reserved characters', () => { - it('produces different location objects', done => { + describe("location created with encoded/unencoded reserved characters", () => { + it("produces different location objects", (done) => { EncodedReservedCharacters(history, done); }); }); - describe('back', () => { - it('calls change listeners with the previous location', done => { + describe("back", () => { + it("calls change listeners with the previous location", (done) => { GoBack(history, done); }); }); - describe('forward', () => { - it('calls change listeners with the next location', done => { + describe("forward", () => { + it("calls change listeners with the next location", (done) => { GoForward(history, done); }); }); - describe('block', () => { - it('blocks all transitions', done => { + describe("block", () => { + it("blocks all transitions", (done) => { BlockEverything(history, done); }); }); - describe('block a POP without listening', () => { - it('receives the next location and action as arguments', done => { + describe("block a POP without listening", () => { + it("receives the next location and action as arguments", (done) => { BlockPopWithoutListening(history, done); }); }); diff --git a/packages/history/__tests__/memory-test.js b/packages/history/__tests__/memory-test.js index fdbf4bdd1..906c68a48 100644 --- a/packages/history/__tests__/memory-test.js +++ b/packages/history/__tests__/memory-test.js @@ -1,172 +1,172 @@ -import expect from 'expect'; -import { createMemoryHistory } from 'history'; - -import Listen from './TestSequences/Listen.js'; -import InitialLocationHasKey from './TestSequences/InitialLocationHasKey.js'; -import PushNewLocation from './TestSequences/PushNewLocation.js'; -import PushSamePath from './TestSequences/PushSamePath.js'; -import PushState from './TestSequences/PushState.js'; -import PushMissingPathname from './TestSequences/PushMissingPathname.js'; -import PushRelativePathnameWarning from './TestSequences/PushRelativePathnameWarning.js'; -import ReplaceNewLocation from './TestSequences/ReplaceNewLocation.js'; -import ReplaceSamePath from './TestSequences/ReplaceSamePath.js'; -import ReplaceState from './TestSequences/ReplaceState.js'; -import EncodedReservedCharacters from './TestSequences/EncodedReservedCharacters.js'; -import GoBack from './TestSequences/GoBack.js'; -import GoForward from './TestSequences/GoForward.js'; -import BlockEverything from './TestSequences/BlockEverything.js'; -import BlockPopWithoutListening from './TestSequences/BlockPopWithoutListening.js'; - -describe('a memory history', () => { +import expect from "expect"; +import { createMemoryHistory } from "history"; + +import Listen from "./TestSequences/Listen.js"; +import InitialLocationHasKey from "./TestSequences/InitialLocationHasKey.js"; +import PushNewLocation from "./TestSequences/PushNewLocation.js"; +import PushSamePath from "./TestSequences/PushSamePath.js"; +import PushState from "./TestSequences/PushState.js"; +import PushMissingPathname from "./TestSequences/PushMissingPathname.js"; +import PushRelativePathnameWarning from "./TestSequences/PushRelativePathnameWarning.js"; +import ReplaceNewLocation from "./TestSequences/ReplaceNewLocation.js"; +import ReplaceSamePath from "./TestSequences/ReplaceSamePath.js"; +import ReplaceState from "./TestSequences/ReplaceState.js"; +import EncodedReservedCharacters from "./TestSequences/EncodedReservedCharacters.js"; +import GoBack from "./TestSequences/GoBack.js"; +import GoForward from "./TestSequences/GoForward.js"; +import BlockEverything from "./TestSequences/BlockEverything.js"; +import BlockPopWithoutListening from "./TestSequences/BlockPopWithoutListening.js"; + +describe("a memory history", () => { let history; beforeEach(() => { history = createMemoryHistory(); }); - it('has an index property', () => { - expect(typeof history.index).toBe('number'); + it("has an index property", () => { + expect(typeof history.index).toBe("number"); }); - it('knows how to create hrefs', () => { + it("knows how to create hrefs", () => { const href = history.createHref({ - pathname: '/the/path', - search: '?the=query', - hash: '#the-hash' + pathname: "/the/path", + search: "?the=query", + hash: "#the-hash", }); - expect(href).toEqual('/the/path?the=query#the-hash'); + expect(href).toEqual("/the/path?the=query#the-hash"); }); - it('knows how to create hrefs from strings', () => { - const href = history.createHref('/the/path?the=query#the-hash'); - expect(href).toEqual('/the/path?the=query#the-hash'); + it("knows how to create hrefs from strings", () => { + const href = history.createHref("/the/path?the=query#the-hash"); + expect(href).toEqual("/the/path?the=query#the-hash"); }); - it('does not encode the generated path', () => { + it("does not encode the generated path", () => { const encodedHref = history.createHref({ - pathname: '/%23abc' + pathname: "/%23abc", }); - expect(encodedHref).toEqual('/%23abc'); + expect(encodedHref).toEqual("/%23abc"); const unencodedHref = history.createHref({ - pathname: '/#abc' + pathname: "/#abc", }); - expect(unencodedHref).toEqual('/#abc'); + expect(unencodedHref).toEqual("/#abc"); }); - describe('listen', () => { - it('does not immediately call listeners', done => { + describe("listen", () => { + it("does not immediately call listeners", (done) => { Listen(history, done); }); }); - describe('the initial location', () => { - it('has a key', done => { + describe("the initial location", () => { + it("has a key", (done) => { InitialLocationHasKey(history, done); }); }); - describe('push a new path', () => { - it('calls change listeners with the new location', done => { + describe("push a new path", () => { + it("calls change listeners with the new location", (done) => { PushNewLocation(history, done); }); }); - describe('push the same path', () => { - it('calls change listeners with the new location', done => { + describe("push the same path", () => { + it("calls change listeners with the new location", (done) => { PushSamePath(history, done); }); }); - describe('push state', () => { - it('calls change listeners with the new location', done => { + describe("push state", () => { + it("calls change listeners with the new location", (done) => { PushState(history, done); }); }); - describe('push with no pathname', () => { - it('reuses the current location pathname', done => { + describe("push with no pathname", () => { + it("reuses the current location pathname", (done) => { PushMissingPathname(history, done); }); }); - describe('push with a relative pathname', () => { - it('issues a warning', done => { + describe("push with a relative pathname", () => { + it("issues a warning", (done) => { PushRelativePathnameWarning(history, done); }); }); - describe('replace a new path', () => { - it('calls change listeners with the new location', done => { + describe("replace a new path", () => { + it("calls change listeners with the new location", (done) => { ReplaceNewLocation(history, done); }); }); - describe('replace the same path', () => { - it('calls change listeners with the new location', done => { + describe("replace the same path", () => { + it("calls change listeners with the new location", (done) => { ReplaceSamePath(history, done); }); }); - describe('replace state', () => { - it('calls change listeners with the new location', done => { + describe("replace state", () => { + it("calls change listeners with the new location", (done) => { ReplaceState(history, done); }); }); - describe('location created with encoded/unencoded reserved characters', () => { - it('produces different location objects', done => { + describe("location created with encoded/unencoded reserved characters", () => { + it("produces different location objects", (done) => { EncodedReservedCharacters(history, done); }); }); - describe('back', () => { - it('calls change listeners with the previous location', done => { + describe("back", () => { + it("calls change listeners with the previous location", (done) => { GoBack(history, done); }); }); - describe('forward', () => { - it('calls change listeners with the next location', done => { + describe("forward", () => { + it("calls change listeners with the next location", (done) => { GoForward(history, done); }); }); - describe('block', () => { - it('blocks all transitions', done => { + describe("block", () => { + it("blocks all transitions", (done) => { BlockEverything(history, done); }); }); - describe('block a POP without listening', () => { - it('receives the next location and action as arguments', done => { + describe("block a POP without listening", () => { + it("receives the next location and action as arguments", (done) => { BlockPopWithoutListening(history, done); }); }); }); -describe('a memory history with some initial entries', () => { - it('clamps the initial index to a valid value', () => { +describe("a memory history with some initial entries", () => { + it("clamps the initial index to a valid value", () => { let history = createMemoryHistory({ - initialEntries: ['/one', '/two', '/three'], - initialIndex: 3 // invalid + initialEntries: ["/one", "/two", "/three"], + initialIndex: 3, // invalid }); expect(history.index).toBe(2); }); - it('starts at the last entry by default', () => { + it("starts at the last entry by default", () => { let history = createMemoryHistory({ - initialEntries: ['/one', '/two', '/three'] + initialEntries: ["/one", "/two", "/three"], }); expect(history.index).toBe(2); expect(history.location).toMatchObject({ - pathname: '/three', - search: '', - hash: '', + pathname: "/three", + search: "", + hash: "", state: null, - key: expect.any(String) + key: expect.any(String), }); }); }); diff --git a/packages/history/browser.ts b/packages/history/browser.ts index 3a08e2e50..ae5ae02d0 100644 --- a/packages/history/browser.ts +++ b/packages/history/browser.ts @@ -1,4 +1,4 @@ -import { createBrowserHistory } from 'history'; +import { createBrowserHistory } from "history"; /** * Create a default instance for the current document. diff --git a/packages/history/hash.ts b/packages/history/hash.ts index 9cd0155e0..a619d5a39 100644 --- a/packages/history/hash.ts +++ b/packages/history/hash.ts @@ -1,4 +1,4 @@ -import { createHashHistory } from 'history'; +import { createHashHistory } from "history"; /** * Create a default instance for the current document. diff --git a/packages/history/index.ts b/packages/history/index.ts index e38d9bbcf..c8cdfc04b 100644 --- a/packages/history/index.ts +++ b/packages/history/index.ts @@ -11,20 +11,20 @@ export enum Action { * * Note: This is the default action for newly created history objects. */ - Pop = 'POP', + Pop = "POP", /** * A PUSH indicates a new entry being added to the history stack, such as when * a link is clicked and a new page loads. When this happens, all subsequent * entries in the stack are lost. */ - Push = 'PUSH', + Push = "PUSH", /** * A REPLACE indicates the entry at the current index in the history stack * being replaced by a new one. */ - Replace = 'REPLACE' + Replace = "REPLACE", } /** @@ -324,7 +324,7 @@ const readOnly: (obj: T) => Readonly = __DEV__ function warning(cond: any, message: string) { if (!cond) { // eslint-disable-next-line no-console - if (typeof console !== 'undefined') console.warn(message); + if (typeof console !== "undefined") console.warn(message); try { // Welcome to debugging history! @@ -348,9 +348,9 @@ type HistoryState = { idx: number; }; -const BeforeUnloadEventType = 'beforeunload'; -const HashChangeEventType = 'hashchange'; -const PopStateEventType = 'popstate'; +const BeforeUnloadEventType = "beforeunload"; +const HashChangeEventType = "hashchange"; +const PopStateEventType = "popstate"; export type BrowserHistoryOptions = { window?: Window }; @@ -377,8 +377,8 @@ export function createBrowserHistory( search, hash, state: state.usr || null, - key: state.key || 'default' - }) + key: state.key || "default", + }), ]; } @@ -401,7 +401,7 @@ export function createBrowserHistory( location: nextLocation, retry() { go(delta * -1); - } + }, }; go(delta); @@ -436,22 +436,22 @@ export function createBrowserHistory( if (index == null) { index = 0; - globalHistory.replaceState({ ...globalHistory.state, idx: index }, ''); + globalHistory.replaceState({ ...globalHistory.state, idx: index }, ""); } function createHref(to: To) { - return typeof to === 'string' ? to : createPath(to); + return typeof to === "string" ? to : createPath(to); } // state defaults to `null` because `window.history.state` does function getNextLocation(to: To, state: any = null): Location { return readOnly({ pathname: location.pathname, - hash: '', - search: '', - ...(typeof to === 'string' ? parsePath(to) : to), + hash: "", + search: "", + ...(typeof to === "string" ? parsePath(to) : to), state, - key: createKey() + key: createKey(), }); } @@ -463,9 +463,9 @@ export function createBrowserHistory( { usr: nextLocation.state, key: nextLocation.key, - idx: index + idx: index, }, - createHref(nextLocation) + createHref(nextLocation), ]; } @@ -494,7 +494,7 @@ export function createBrowserHistory( // TODO: Support forced reloading // try...catch because iOS limits us to 100 pushState calls :/ try { - globalHistory.pushState(historyState, '', url); + globalHistory.pushState(historyState, "", url); } catch (error) { // They are going to lose state here, but there is no real // way to warn them about it since the page will refresh... @@ -516,7 +516,7 @@ export function createBrowserHistory( let [historyState, url] = getHistoryStateAndUrl(nextLocation, index); // TODO: Support forced reloading - globalHistory.replaceState(historyState, '', url); + globalHistory.replaceState(historyState, "", url); applyTx(nextAction); } @@ -563,7 +563,7 @@ export function createBrowserHistory( window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload); } }; - } + }, }; return history; @@ -591,9 +591,9 @@ export function createHashHistory( function getIndexAndLocation(): [number, Location] { let { - pathname = '/', - search = '', - hash = '' + pathname = "/", + search = "", + hash = "", } = parsePath(window.location.hash.substr(1)); let state = globalHistory.state || {}; return [ @@ -603,8 +603,8 @@ export function createHashHistory( search, hash, state: state.usr || null, - key: state.key || 'default' - }) + key: state.key || "default", + }), ]; } @@ -627,7 +627,7 @@ export function createHashHistory( location: nextLocation, retry() { go(delta * -1); - } + }, }; go(delta); @@ -673,16 +673,16 @@ export function createHashHistory( if (index == null) { index = 0; - globalHistory.replaceState({ ...globalHistory.state, idx: index }, ''); + globalHistory.replaceState({ ...globalHistory.state, idx: index }, ""); } function getBaseHref() { - let base = document.querySelector('base'); - let href = ''; + let base = document.querySelector("base"); + let href = ""; - if (base && base.getAttribute('href')) { + if (base && base.getAttribute("href")) { let url = window.location.href; - let hashIndex = url.indexOf('#'); + let hashIndex = url.indexOf("#"); href = hashIndex === -1 ? url : url.slice(0, hashIndex); } @@ -690,17 +690,17 @@ export function createHashHistory( } function createHref(to: To) { - return getBaseHref() + '#' + (typeof to === 'string' ? to : createPath(to)); + return getBaseHref() + "#" + (typeof to === "string" ? to : createPath(to)); } function getNextLocation(to: To, state: any = null): Location { return readOnly({ pathname: location.pathname, - hash: '', - search: '', - ...(typeof to === 'string' ? parsePath(to) : to), + hash: "", + search: "", + ...(typeof to === "string" ? parsePath(to) : to), state, - key: createKey() + key: createKey(), }); } @@ -712,9 +712,9 @@ export function createHashHistory( { usr: nextLocation.state, key: nextLocation.key, - idx: index + idx: index, }, - createHref(nextLocation) + createHref(nextLocation), ]; } @@ -738,7 +738,7 @@ export function createHashHistory( } warning( - nextLocation.pathname.charAt(0) === '/', + nextLocation.pathname.charAt(0) === "/", `Relative pathnames are not supported in hash history.push(${JSON.stringify( to )})` @@ -750,7 +750,7 @@ export function createHashHistory( // TODO: Support forced reloading // try...catch because iOS limits us to 100 pushState calls :/ try { - globalHistory.pushState(historyState, '', url); + globalHistory.pushState(historyState, "", url); } catch (error) { // They are going to lose state here, but there is no real // way to warn them about it since the page will refresh... @@ -769,7 +769,7 @@ export function createHashHistory( } warning( - nextLocation.pathname.charAt(0) === '/', + nextLocation.pathname.charAt(0) === "/", `Relative pathnames are not supported in hash history.replace(${JSON.stringify( to )})` @@ -779,7 +779,7 @@ export function createHashHistory( let [historyState, url] = getHistoryStateAndUrl(nextLocation, index); // TODO: Support forced reloading - globalHistory.replaceState(historyState, '', url); + globalHistory.replaceState(historyState, "", url); applyTx(nextAction); } @@ -826,7 +826,7 @@ export function createHashHistory( window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload); } }; - } + }, }; return history; @@ -856,19 +856,19 @@ export type MemoryHistoryOptions = { export function createMemoryHistory( options: MemoryHistoryOptions = {} ): MemoryHistory { - let { initialEntries = ['/'], initialIndex } = options; + let { initialEntries = ["/"], initialIndex } = options; let entries: Location[] = initialEntries.map((entry) => { let location = readOnly({ - pathname: '/', - search: '', - hash: '', + pathname: "/", + search: "", + hash: "", state: null, key: createKey(), - ...(typeof entry === 'string' ? parsePath(entry) : entry) + ...(typeof entry === "string" ? parsePath(entry) : entry), }); warning( - location.pathname.charAt(0) === '/', + location.pathname.charAt(0) === "/", `Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: ${JSON.stringify( entry )})` @@ -888,17 +888,17 @@ export function createMemoryHistory( let blockers = createEvents(); function createHref(to: To) { - return typeof to === 'string' ? to : createPath(to); + return typeof to === "string" ? to : createPath(to); } function getNextLocation(to: To, state: any = null): Location { return readOnly({ pathname: location.pathname, - search: '', - hash: '', - ...(typeof to === 'string' ? parsePath(to) : to), + search: "", + hash: "", + ...(typeof to === "string" ? parsePath(to) : to), state, - key: createKey() + key: createKey(), }); } @@ -922,7 +922,7 @@ export function createMemoryHistory( } warning( - location.pathname.charAt(0) === '/', + location.pathname.charAt(0) === "/", `Relative pathnames are not supported in memory history.push(${JSON.stringify( to )})` @@ -943,7 +943,7 @@ export function createMemoryHistory( } warning( - location.pathname.charAt(0) === '/', + location.pathname.charAt(0) === "/", `Relative pathnames are not supported in memory history.replace(${JSON.stringify( to )})` @@ -994,7 +994,7 @@ export function createMemoryHistory( }, block(blocker) { return blockers.push(blocker); - } + }, }; return history; @@ -1012,7 +1012,7 @@ function promptBeforeUnload(event: BeforeUnloadEvent) { // Cancel the event. event.preventDefault(); // Chrome (and legacy IE) requires returnValue to be set. - event.returnValue = ''; + event.returnValue = ""; } type Events = { @@ -1036,7 +1036,7 @@ function createEvents(): Events { }, call(arg) { handlers.forEach((fn) => fn && fn(arg)); - } + }, }; } @@ -1050,14 +1050,14 @@ function createKey() { * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createpath */ export function createPath({ - pathname = '/', - search = '', - hash = '' + pathname = "/", + search = "", + hash = "", }: Partial) { - if (search && search !== '?') - pathname += search.charAt(0) === '?' ? search : '?' + search; - if (hash && hash !== '#') - pathname += hash.charAt(0) === '#' ? hash : '#' + hash; + if (search && search !== "?") + pathname += search.charAt(0) === "?" ? search : "?" + search; + if (hash && hash !== "#") + pathname += hash.charAt(0) === "#" ? hash : "#" + hash; return pathname; } @@ -1070,13 +1070,13 @@ export function parsePath(path: string): Partial { let parsedPath: Partial = {}; if (path) { - let hashIndex = path.indexOf('#'); + let hashIndex = path.indexOf("#"); if (hashIndex >= 0) { parsedPath.hash = path.substr(hashIndex); path = path.substr(0, hashIndex); } - let searchIndex = path.indexOf('?'); + let searchIndex = path.indexOf("?"); if (searchIndex >= 0) { parsedPath.search = path.substr(searchIndex); path = path.substr(0, searchIndex); diff --git a/packages/history/node-main.js b/packages/history/node-main.js index d2440db40..684ed3255 100644 --- a/packages/history/node-main.js +++ b/packages/history/node-main.js @@ -1,7 +1,7 @@ /* eslint-env node */ -if (process.env.NODE_ENV === 'production') { - module.exports = require('./umd/history.production.min.js'); +if (process.env.NODE_ENV === "production") { + module.exports = require("./umd/history.production.min.js"); } else { - module.exports = require('./umd/history.development.js'); + module.exports = require("./umd/history.development.js"); } diff --git a/scripts/build.js b/scripts/build.js index 794ef4e23..ee787286d 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -1,9 +1,9 @@ -const path = require('path'); -const execSync = require('child_process').execSync; +const path = require("path"); +const execSync = require("child_process").execSync; -let config = path.resolve(__dirname, 'rollup/history.config.js'); +let config = path.resolve(__dirname, "rollup/history.config.js"); execSync(`rollup -c ${config}`, { env: process.env, - stdio: 'inherit' + stdio: "inherit", }); diff --git a/scripts/karma.conf.js b/scripts/karma.conf.js index 59d983046..066676c2a 100644 --- a/scripts/karma.conf.js +++ b/scripts/karma.conf.js @@ -1,15 +1,15 @@ -var path = require('path'); -var webpack = require('webpack'); +var path = require("path"); +var webpack = require("webpack"); module.exports = function (config) { var customLaunchers = { BS_Chrome: { - name: 'Chrome', - base: 'BrowserStack', - os: 'Windows', - os_version: '10', - browser: 'Chrome', - browser_version: '73.0' + name: "Chrome", + base: "BrowserStack", + os: "Windows", + os_version: "10", + browser: "Chrome", + browser_version: "73.0", }, // BS_ChromeAndroid: { // base: 'BrowserStack', @@ -18,29 +18,29 @@ module.exports = function (config) { // real_mobile: true // }, BS_Firefox: { - name: 'Firefox', - base: 'BrowserStack', - os: 'Windows', - os_version: '10', - browser: 'Firefox', - browser_version: '67.0' + name: "Firefox", + base: "BrowserStack", + os: "Windows", + os_version: "10", + browser: "Firefox", + browser_version: "67.0", }, BS_Edge: { - name: 'Edge', - base: 'BrowserStack', - os: 'Windows', - os_version: '10', - browser: 'Edge', - browser_version: '17.0' + name: "Edge", + base: "BrowserStack", + os: "Windows", + os_version: "10", + browser: "Edge", + browser_version: "17.0", }, BS_IE11: { - name: 'IE 11', - base: 'BrowserStack', - os: 'Windows', - os_version: '10', - browser: 'IE', - browser_version: '11.0' - } + name: "IE 11", + base: "BrowserStack", + os: "Windows", + os_version: "10", + browser: "IE", + browser_version: "11.0", + }, // Safari throws an error if you use replaceState more // than 100 times in 30 seconds :/ // BS_Safari: { @@ -67,22 +67,22 @@ module.exports = function (config) { config.set({ singleRun: true, customLaunchers: customLaunchers, - browsers: ['Chrome' /*, 'Firefox'*/], - frameworks: ['mocha' /*, 'webpack' */], - reporters: ['mocha'], - files: ['tests.webpack.js'], + browsers: ["Chrome" /*, 'Firefox'*/], + frameworks: ["mocha" /*, 'webpack' */], + reporters: ["mocha"], + files: ["tests.webpack.js"], preprocessors: { - 'tests.webpack.js': ['webpack', 'sourcemap'] + "tests.webpack.js": ["webpack", "sourcemap"], }, webpack: { // TODO: Webpack 4+ // mode: 'none', - devtool: 'inline-source-map', + devtool: "inline-source-map", resolve: { - modules: [path.resolve(__dirname, '../'), 'node_modules'], + modules: [path.resolve(__dirname, "../"), "node_modules"], alias: { - history: path.resolve(__dirname, '../build/history') - } + history: path.resolve(__dirname, "../build/history"), + }, }, module: { rules: [ @@ -90,40 +90,40 @@ module.exports = function (config) { test: /__tests__\/.*\.js$/, exclude: /node_modules/, use: { - loader: 'babel-loader', + loader: "babel-loader", options: { - presets: ['@babel/preset-env'] - } - } - } - ] + presets: ["@babel/preset-env"], + }, + }, + }, + ], }, plugins: [ new webpack.DefinePlugin({ - 'process.env.NODE_ENV': JSON.stringify('test') - }) - ] + "process.env.NODE_ENV": JSON.stringify("test"), + }), + ], }, webpackServer: { - noInfo: true - } + noInfo: true, + }, }); if (process.env.TRAVIS || process.env.USE_CLOUD) { config.browsers = Object.keys(customLaunchers); - config.reporters = ['dots']; + config.reporters = ["dots"]; config.concurrency = 2; config.browserDisconnectTimeout = 10000; config.browserDisconnectTolerance = 3; if (process.env.TRAVIS) { config.browserStack = { - project: 'history', - build: process.env.TRAVIS_BRANCH + project: "history", + build: process.env.TRAVIS_BRANCH, }; } else { config.browserStack = { - project: 'history' + project: "history", }; } } diff --git a/scripts/publish.js b/scripts/publish.js index 506527d26..df8604dc8 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -1,22 +1,22 @@ -const path = require('path'); -const execSync = require('child_process').execSync; +const path = require("path"); +const execSync = require("child_process").execSync; -const jsonfile = require('jsonfile'); -const semver = require('semver'); +const jsonfile = require("jsonfile"); +const semver = require("semver"); -const rootDir = path.resolve(__dirname, '..'); +const rootDir = path.resolve(__dirname, ".."); function invariant(cond, message) { if (!cond) throw new Error(message); } function getTaggedVersion() { - let output = execSync('git tag --list --points-at HEAD').toString(); - return output.replace(/^v|\n+$/g, ''); + let output = execSync("git tag --list --points-at HEAD").toString(); + return output.replace(/^v|\n+$/g, ""); } async function ensureBuildVersion(packageName, version) { - let file = path.join(rootDir, 'build', packageName, 'package.json'); + let file = path.join(rootDir, "build", packageName, "package.json"); let json = await jsonfile.readFile(file); invariant( json.version === version, @@ -25,11 +25,11 @@ async function ensureBuildVersion(packageName, version) { } function publishBuild(packageName, tag) { - let buildDir = path.join(rootDir, 'build', packageName); + let buildDir = path.join(rootDir, "build", packageName); console.log(); console.log(` npm publish ${buildDir} --tag ${tag}`); console.log(); - execSync(`npm publish ${buildDir} --tag ${tag}`, { stdio: 'inherit' }); + execSync(`npm publish ${buildDir} --tag ${tag}`, { stdio: "inherit" }); } async function run() { @@ -43,21 +43,21 @@ async function run() { // 1. Get the current tag, which has the release version number let version = getTaggedVersion(); invariant( - version !== '', - 'Missing release version. Run the version script first.' + version !== "", + "Missing release version. Run the version script first." ); // 2. Determine the appropriate npm tag to use - let tag = semver.prerelease(version) == null ? 'latest' : 'next'; + let tag = semver.prerelease(version) == null ? "latest" : "next"; console.log(); console.log(` Publishing version ${version} to npm with tag "${tag}"`); // 3. Ensure build versions match the release version - await ensureBuildVersion('history', version); + await ensureBuildVersion("history", version); // 4. Publish to npm - publishBuild('history', tag); + publishBuild("history", tag); } catch (error) { console.log(); console.error(` ${error.message}`); @@ -68,6 +68,6 @@ async function run() { return 0; } -run().then(code => { +run().then((code) => { process.exit(code); }); diff --git a/scripts/rollup/history.config.js b/scripts/rollup/history.config.js index 2efb94f87..0eee11fbd 100644 --- a/scripts/rollup/history.config.js +++ b/scripts/rollup/history.config.js @@ -1,77 +1,77 @@ -import { babel } from '@rollup/plugin-babel'; -import copy from 'rollup-plugin-copy'; -import prettier from 'rollup-plugin-prettier'; -import replace from '@rollup/plugin-replace'; -import { terser } from 'rollup-plugin-terser'; -import typescript from 'rollup-plugin-typescript2'; +import { babel } from "@rollup/plugin-babel"; +import copy from "rollup-plugin-copy"; +import prettier from "rollup-plugin-prettier"; +import replace from "@rollup/plugin-replace"; +import { terser } from "rollup-plugin-terser"; +import typescript from "rollup-plugin-typescript2"; const PRETTY = !!process.env.PRETTY; -const SOURCE_DIR = 'packages/history'; -const OUTPUT_DIR = 'build/history'; +const SOURCE_DIR = "packages/history"; +const OUTPUT_DIR = "build/history"; const modules = [ { input: `${SOURCE_DIR}/index.ts`, output: { file: `${OUTPUT_DIR}/index.js`, - format: 'esm', - sourcemap: !PRETTY + format: "esm", + sourcemap: !PRETTY, }, - external: ['@babel/runtime/helpers/esm/extends'], + external: ["@babel/runtime/helpers/esm/extends"], plugins: [ typescript({ tsconfigDefaults: { compilerOptions: { - declaration: true - } - } + declaration: true, + }, + }, }), babel({ exclude: /node_modules/, - extensions: ['.ts'], - presets: [['@babel/preset-env', { loose: true }]], + extensions: [".ts"], + presets: [["@babel/preset-env", { loose: true }]], plugins: [ - 'babel-plugin-dev-expression', - ['@babel/plugin-transform-runtime', { useESModules: true }] + "babel-plugin-dev-expression", + ["@babel/plugin-transform-runtime", { useESModules: true }], ], - babelHelpers: 'runtime' + babelHelpers: "runtime", }), copy({ targets: [ - { src: 'README.md', dest: OUTPUT_DIR }, - { src: 'LICENSE', dest: OUTPUT_DIR }, - { src: `${SOURCE_DIR}/package.json`, dest: OUTPUT_DIR } + { src: "README.md", dest: OUTPUT_DIR }, + { src: "LICENSE", dest: OUTPUT_DIR }, + { src: `${SOURCE_DIR}/package.json`, dest: OUTPUT_DIR }, ], - verbose: true - }) - ].concat(PRETTY ? prettier({ parser: 'babel' }) : []) + verbose: true, + }), + ].concat(PRETTY ? prettier({ parser: "babel" }) : []), }, - ...['browser', 'hash'].map((env) => { + ...["browser", "hash"].map((env) => { return { input: `${SOURCE_DIR}/${env}.ts`, output: { file: `${OUTPUT_DIR}/${env}.js`, - format: 'esm', - sourcemap: !PRETTY + format: "esm", + sourcemap: !PRETTY, }, plugins: [ typescript({ tsconfigDefaults: { compilerOptions: { - declaration: true - } - } + declaration: true, + }, + }, }), babel({ exclude: /node_modules/, - extensions: ['.ts'], - presets: [['@babel/preset-env', { loose: true }]], - plugins: ['babel-plugin-dev-expression'], - babelHelpers: 'bundled' - }) - ].concat(PRETTY ? prettier({ parser: 'babel' }) : []) + extensions: [".ts"], + presets: [["@babel/preset-env", { loose: true }]], + plugins: ["babel-plugin-dev-expression"], + babelHelpers: "bundled", + }), + ].concat(PRETTY ? prettier({ parser: "babel" }) : []), }; - }) + }), ]; const webModules = [ @@ -79,59 +79,59 @@ const webModules = [ input: `${SOURCE_DIR}/index.ts`, output: { file: `${OUTPUT_DIR}/history.development.js`, - format: 'esm', - sourcemap: !PRETTY + format: "esm", + sourcemap: !PRETTY, }, plugins: [ typescript({ tsconfigOverride: { compilerOptions: { - target: 'es2016' - } - } + target: "es2016", + }, + }, }), babel({ exclude: /node_modules/, - extensions: ['.ts'], - presets: ['@babel/preset-modules'], - plugins: ['babel-plugin-dev-expression'], - babelHelpers: 'bundled' + extensions: [".ts"], + presets: ["@babel/preset-modules"], + plugins: ["babel-plugin-dev-expression"], + babelHelpers: "bundled", }), replace({ - 'process.env.NODE_ENV': JSON.stringify('development'), - preventAssignment: false - }) - ].concat(PRETTY ? prettier({ parser: 'babel' }) : []) + "process.env.NODE_ENV": JSON.stringify("development"), + preventAssignment: false, + }), + ].concat(PRETTY ? prettier({ parser: "babel" }) : []), }, { input: `${SOURCE_DIR}/index.ts`, output: { file: `${OUTPUT_DIR}/history.production.min.js`, - format: 'esm', - sourcemap: !PRETTY + format: "esm", + sourcemap: !PRETTY, }, plugins: [ typescript({ tsconfigOverride: { compilerOptions: { - target: 'es2016' - } - } + target: "es2016", + }, + }, }), babel({ exclude: /node_modules/, - extensions: ['.ts'], - presets: ['@babel/preset-modules'], - plugins: ['babel-plugin-dev-expression'], - babelHelpers: 'bundled' + extensions: [".ts"], + presets: ["@babel/preset-modules"], + plugins: ["babel-plugin-dev-expression"], + babelHelpers: "bundled", }), replace({ - 'process.env.NODE_ENV': JSON.stringify('production'), - preventAssignment: false + "process.env.NODE_ENV": JSON.stringify("production"), + preventAssignment: false, }), - terser({ ecma: 8, safari10: true }) - ].concat(PRETTY ? prettier({ parser: 'babel' }) : []) - } + terser({ ecma: 8, safari10: true }), + ].concat(PRETTY ? prettier({ parser: "babel" }) : []), + }, ]; const globals = [ @@ -139,49 +139,49 @@ const globals = [ input: `${SOURCE_DIR}/index.ts`, output: { file: `${OUTPUT_DIR}/umd/history.development.js`, - format: 'umd', + format: "umd", sourcemap: !PRETTY, - name: 'HistoryLibrary' + name: "HistoryLibrary", }, plugins: [ typescript(), babel({ exclude: /node_modules/, - extensions: ['.ts'], - presets: [['@babel/preset-env', { loose: true }]], - plugins: ['babel-plugin-dev-expression'], - babelHelpers: 'bundled' + extensions: [".ts"], + presets: [["@babel/preset-env", { loose: true }]], + plugins: ["babel-plugin-dev-expression"], + babelHelpers: "bundled", }), replace({ - 'process.env.NODE_ENV': JSON.stringify('development'), - preventAssignment: false - }) - ].concat(PRETTY ? prettier({ parser: 'babel' }) : []) + "process.env.NODE_ENV": JSON.stringify("development"), + preventAssignment: false, + }), + ].concat(PRETTY ? prettier({ parser: "babel" }) : []), }, { input: `${SOURCE_DIR}/index.ts`, output: { file: `${OUTPUT_DIR}/umd/history.production.min.js`, - format: 'umd', + format: "umd", sourcemap: !PRETTY, - name: 'HistoryLibrary' + name: "HistoryLibrary", }, plugins: [ typescript(), babel({ exclude: /node_modules/, - extensions: ['.ts'], - presets: [['@babel/preset-env', { loose: true }]], - plugins: ['babel-plugin-dev-expression'], - babelHelpers: 'bundled' + extensions: [".ts"], + presets: [["@babel/preset-env", { loose: true }]], + plugins: ["babel-plugin-dev-expression"], + babelHelpers: "bundled", }), replace({ - 'process.env.NODE_ENV': JSON.stringify('production'), - preventAssignment: false + "process.env.NODE_ENV": JSON.stringify("production"), + preventAssignment: false, }), - terser() - ].concat(PRETTY ? prettier({ parser: 'babel' }) : []) - } + terser(), + ].concat(PRETTY ? prettier({ parser: "babel" }) : []), + }, ]; const node = [ @@ -189,10 +189,10 @@ const node = [ input: `${SOURCE_DIR}/node-main.js`, output: { file: `${OUTPUT_DIR}/main.js`, - format: 'cjs' + format: "cjs", }, - plugins: PRETTY ? prettier({ parser: 'babel' }) : [] - } + plugins: PRETTY ? prettier({ parser: "babel" }) : [], + }, ]; const config = [...modules, ...webModules, ...globals, ...node]; diff --git a/scripts/test.js b/scripts/test.js index 0ac6a795c..c78f21c55 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -1,9 +1,9 @@ -const path = require('path'); -const execSync = require('child_process').execSync; +const path = require("path"); +const execSync = require("child_process").execSync; -let karmaConfig = path.resolve(__dirname, 'karma.conf.js'); +let karmaConfig = path.resolve(__dirname, "karma.conf.js"); execSync(`karma start ${karmaConfig}`, { env: process.env, - stdio: 'inherit' + stdio: "inherit", }); diff --git a/scripts/tests.webpack.js b/scripts/tests.webpack.js index 118b229e8..135ef21e7 100644 --- a/scripts/tests.webpack.js +++ b/scripts/tests.webpack.js @@ -1,2 +1,2 @@ -var context = require.context('../packages', true, /-test\.js$/); +var context = require.context("../packages", true, /-test\.js$/); context.keys().forEach(context); diff --git a/scripts/version.js b/scripts/version.js index cda1ce77b..5aba4dcab 100644 --- a/scripts/version.js +++ b/scripts/version.js @@ -1,15 +1,15 @@ -const path = require('path'); -const execSync = require('child_process').execSync; +const path = require("path"); +const execSync = require("child_process").execSync; -const chalk = require('chalk'); -const Confirm = require('prompt-confirm'); -const jsonfile = require('jsonfile'); -const semver = require('semver'); +const chalk = require("chalk"); +const Confirm = require("prompt-confirm"); +const jsonfile = require("jsonfile"); +const semver = require("semver"); -const rootDir = path.resolve(__dirname, '..'); +const rootDir = path.resolve(__dirname, ".."); function packageJson(packageName) { - return path.join(rootDir, 'packages', packageName, 'package.json'); + return path.join(rootDir, "packages", packageName, "package.json"); } function invariant(cond, message) { @@ -17,13 +17,11 @@ function invariant(cond, message) { } function ensureCleanWorkingDirectory() { - let status = execSync(`git status --porcelain`) - .toString() - .trim(); - let lines = status.split('\n'); + let status = execSync(`git status --porcelain`).toString().trim(); + let lines = status.split("\n"); invariant( - lines.every(line => line === '' || line.startsWith('?')), - 'Working directory is not clean. Please commit or stash your changes.' + lines.every((line) => line === "" || line.startsWith("?")), + "Working directory is not clean. Please commit or stash your changes." ); } @@ -76,7 +74,7 @@ async function run() { ensureCleanWorkingDirectory(); // 1. Get the next version number - let currentVersion = await getPackageVersion('history'); + let currentVersion = await getPackageVersion("history"); let version = semver.valid(givenVersion); if (version == null) { version = getNextVersion(currentVersion, givenVersion, prereleaseId); @@ -90,7 +88,7 @@ async function run() { if (answer === false) return 0; // 3. Update history version - await updatePackageConfig('history', config => { + await updatePackageConfig("history", (config) => { config.version = version; }); console.log(chalk.green(` Updated history to version ${version}`)); @@ -109,6 +107,6 @@ async function run() { return 0; } -run().then(code => { +run().then((code) => { process.exit(code); });