Skip to content

Commit 36bd0f8

Browse files
committed
work in progress
1 parent 4bb770d commit 36bd0f8

File tree

8 files changed

+79
-484
lines changed

8 files changed

+79
-484
lines changed

packages/use-hash-history/__debug__/TestSequences/PushRelativePathnameWarning.js

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
11
import { suite } from "uvu";
2-
import * as chai from 'chai';
2+
import * as assert from 'uvu/assert';
33
import * as ENV from "./setup/env.js";
44
import { useHashHistory } from "../index.ts";
55

6-
import PushRelativePathnameWarning from './TestSequences/PushRelativePathnameWarning.js';
7-
86
const TestUseHistory = suite("test history hook");
97

108
TestUseHistory.before.each(ENV.reset);
119

10+
/*
11+
* Roundtrip test of pathname update
12+
*/
13+
const testLocationPathname = async ({ fn, listen, input }) => {
14+
return new Promise((resolve) => {
15+
listen(({ location }) => {
16+
resolve(location.pathname);
17+
});
18+
fn(input);
19+
});
20+
};
21+
1222
TestUseHistory("Runs", async () => {
1323
debugger
14-
const history = useHashHistory({hashRoot:"/"})
15-
chai.expect(() => {
16-
PushRelativePathnameWarning(history, (e) => {
17-
if (e) {
18-
throw(e)
19-
}
20-
})
21-
}).to.not.throw()
24+
const history = useHashHistory({hashRoot:"/"})
25+
26+
await testLocationPathname({
27+
fn: history.push,
28+
listen: history.listen,
29+
input: '/the/path?the=query#the-hash'
30+
})
31+
32+
await testLocationPathname({
33+
fn: history.push,
34+
listen: history.listen,
35+
input: '../other/path?another=query#another-hash'
36+
})
37+
38+
const pathname = await testLocationPathname({
39+
fn: history.push,
40+
listen: history.listen,
41+
input: '../other/path?another=query#another-hash'
42+
})
43+
44+
assert.is(pathname, '../other/path?another=query#another-hash')
2245
});
2346

2447
TestUseHistory.run();

packages/use-hash-history/__debug__/setup/env.js

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,41 +55,9 @@ const makeGlobalDocument = () => {
5555
});
5656
};
5757

58-
class ExecSteps {
59-
60-
constructor ({listen, location}) {
61-
this.listen = listen
62-
this.ctx = {
63-
location
64-
}
65-
}
66-
steps (steps, history, done) {
67-
steps.reduce(async (context, step) => {
68-
this.ctx = await context;
69-
return await new Promise((resolve) => {
70-
this.listen((result) => {
71-
resolve({
72-
...this.ctx, ...result
73-
});
74-
});
75-
step(this.ctx)
76-
});
77-
}, this.ctx).then((result) => {
78-
done(result)
79-
}).catch((e) => {
80-
done(e)
81-
});
82-
}
83-
}
84-
8558
export function reset() {
8659
const newGlobal = {
8760
document: makeGlobalDocument()
8861
};
8962
global.document = newGlobal.document;
90-
const window = document.defaultView;
91-
const {listen, location} = window.history;
92-
93-
const exec = new ExecSteps({listen, location})
94-
global.execSteps = exec.steps.bind(exec)
9563
}

packages/use-hash-history/__tests__/TestSequences/PushRelativePathnameWarning.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import { execSteps, spyOn } from './utils.js';
55
export default (history, done) => {
66
let steps = [
77
({ location }) => {
8+
console.warn({warn: 1, ...location})
89
expect(location).toMatchObject({
910
pathname: '/'
1011
});
1112

1213
history.push('/the/path?the=query#the-hash');
1314
},
1415
({ action, location }) => {
16+
console.warn({warn: 2, ...location})
1517
expect(action).toBe('PUSH');
1618
expect(location).toMatchObject({
1719
pathname: '/the/path?the=query#the-hash',
@@ -21,14 +23,14 @@ export default (history, done) => {
2123

2224
let { spy, destroy } = spyOn(console, 'warn');
2325

24-
debugger
2526
history.push('../other/path?another=query#another-hash');
2627

2728
expect(spy).not.toHaveBeenCalled();
2829

2930
destroy();
3031
},
3132
({ location }) => {
33+
console.warn({warn: 3, ...location})
3234
expect(location).toMatchObject({
3335
pathname: '../other/path?another=query#another-hash',
3436
search: '',

packages/use-hash-history/package.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,5 @@
2929
],
3030
"peerDependencies": {
3131
"history": "5.x"
32-
},
33-
"devDependencies": {
34-
"chai": "^4.3.4",
35-
"esm": "^3.2.25",
36-
"history": "^5.1.0",
37-
"linkedom": "^0.13.0",
38-
"tsm": "^2.2.1",
39-
"uvu": "^0.5.2"
4032
}
4133
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "use-hash-history",
3+
"version": "1.0.1",
4+
"description": "A history hook for react-router-dom",
5+
"license": "MIT",
6+
"author": "John T. Hoffer",
7+
"repository": "github:thejohnhoffer/use-hash-history",
8+
"contributors": [
9+
{
10+
"name": "React Training",
11+
"email": "[email protected]"
12+
}
13+
],
14+
"scripts": {
15+
"debug": "node --inspect-brk node_modules/uvu/bin.js -r tsm -r esm __debug__"
16+
},
17+
"type": "module",
18+
"main": "main.js",
19+
"module": "index.js",
20+
"types": "index.d.ts",
21+
"unpkg": "umd/history.production.min.js",
22+
"sideEffects": false,
23+
"dependencies": {
24+
"@babel/runtime": "^7.7.6"
25+
},
26+
"keywords": [
27+
"history",
28+
"location"
29+
],
30+
"peerDependencies": {
31+
"history": "5.x"
32+
},
33+
"devDependencies": {
34+
"esm": "^3.2.25",
35+
"history": "^5.1.0",
36+
"linkedom": "^0.13.0",
37+
"tsm": "^2.2.1",
38+
"uvu": "^0.5.2"
39+
}
40+
}

0 commit comments

Comments
 (0)