Skip to content

Commit 04171f6

Browse files
committed
add a test config for Chrome
1 parent 335ce4d commit 04171f6

File tree

11 files changed

+2257
-543
lines changed

11 files changed

+2257
-543
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ coverage
77

88
/*.js
99
/*.ts
10+

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Node.js CI
22

33
on:
44
push:
5-
branches: [$default-branch]
5+
branches: [main]
66
pull_request:
7-
branches: [$default-branch]
7+
branches: [main]
88

99
jobs:
1010
build:
@@ -25,6 +25,7 @@ jobs:
2525

2626
test:
2727
runs-on: ubuntu-latest
28+
timeout-minutes: 5
2829

2930
strategy:
3031
matrix:
@@ -38,6 +39,8 @@ jobs:
3839
node-version: ${{ matrix.node-version }}
3940
- run: yarn
4041
- run: yarn test
42+
env:
43+
DISPLAY: :0
4144

4245
lint:
4346
runs-on: ubuntu-latest

.github/workflows/publish.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,7 @@ on:
88
types: [created]
99

1010
jobs:
11-
test:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v2
15-
- uses: actions/setup-node@v2
16-
with:
17-
node-version: "14.x"
18-
- run: yarn
19-
- run: yarn test
20-
2111
publish-npm:
22-
needs: test
2312
runs-on: ubuntu-latest
2413
steps:
2514
- uses: actions/checkout@v2
@@ -34,7 +23,6 @@ jobs:
3423
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
3524

3625
publish-gpr:
37-
needs: test
3826
runs-on: ubuntu-latest
3927
steps:
4028
- uses: actions/checkout@v2

.vscode/launch.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"name": "Debug Jest Tests",
9+
"type": "node",
10+
"request": "launch",
11+
"runtimeArgs": [
12+
"--inspect-brk=9229",
13+
"${workspaceRoot}/node_modules/.bin/jest",
14+
"--runInBand"
15+
],
16+
"console": "integratedTerminal",
17+
"internalConsoleOptions": "neverOpen",
18+
"port": 9229,
19+
"sourceMaps": true,
20+
"disableOptimisticBPs": true
21+
},
722
{
823
"type": "pwa-node",
924
"request": "launch",
@@ -12,7 +27,7 @@
1227
"program": "${file}",
1328
// "program": "${workspaceFolder}${pathSeparator}dist${pathSeparator}${fileBasenameNoExtension}.js",
1429
// "args": ["--experimental-modules"],
15-
"preLaunchTask": "tsc: build - tsconfig.debug.json",
30+
"preLaunchTask": "tsc: build - tsconfig.json",
1631
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
1732
}
1833
]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> **Unstable now, use it at your own risk**
44
5-
href is a lib for working with incomplete URLs (without a base) in the builtin [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL)'s way
5+
href is a lib for working with incomplete (without a base) URLs in the builtin [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL)'s way
66

77
## Usage
88

@@ -30,8 +30,8 @@ It behaviors like the builtin URL API:
3030
- When using `Href` with other incomplete URLs, only `href`, `pathname`, `search`, `searchParams`, `hash` will work
3131
- `new Href('path/to/file1?q=1').searchParams.set('q','2')`
3232
- `new Href('file2', 'path/to/file1').pathname === 'path/to/file2'`
33-
- `new Href('file2', 'path/').pathname === 'path/to/file2'`
34-
- `new Href('../../file2')'`
33+
- `new Href('file2', 'path/').pathname === 'path/file2'`
34+
- `new Href('../../file2')` keeps `../../`
3535

3636
## Credits
3737

jest.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
projects: [
88
{
99
displayName: 'jsdom',
10-
testEnvironment: './custom-test-environment.js',
10+
testEnvironment: './jsdom-test-environment.js',
1111
clearMocks: true,
1212
globals: {
1313
'ts-jest': {
@@ -30,5 +30,11 @@ export default {
3030
preset: 'ts-jest',
3131
testPathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/node_modules/'],
3232
},
33+
{
34+
displayName: 'electron',
35+
runner: '@jest-runner/electron',
36+
testEnvironment: '@jest-runner/electron/environment',
37+
transform: { '\\.ts$': 'ts-jest' },
38+
},
3339
],
3440
};

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lonr/href",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "href is a lib for working with incomplete URLs (without a base) in the builtin URL's way",
55
"type": "commonjs",
66
"main": "./dist/index.js",
@@ -42,10 +42,12 @@
4242
"path"
4343
],
4444
"devDependencies": {
45+
"@jest-runner/electron": "^3.0.0",
4546
"@rollup/plugin-commonjs": "^17.1.0",
4647
"@types/jest": "^26.0.20",
4748
"@typescript-eslint/eslint-plugin": "^4.14.2",
4849
"@typescript-eslint/parser": "^4.14.2",
50+
"electron": "^11.2.3",
4951
"eslint": "^7.19.0",
5052
"eslint-config-prettier": "^7.2.0",
5153
"husky": "^5.0.9",
@@ -61,10 +63,7 @@
6163
"ts-jest": "^26.5.0",
6264
"ts-node": "^9.1.1",
6365
"tslib": "^2.1.0",
64-
"typescript": "^4.1.3",
65-
"webpack": "^5.20.0",
66-
"webpack-cli": "^4.5.0",
67-
"whatwg-url": "^8.4.0"
66+
"typescript": "^4.1.3"
6867
},
6968
"dependencies": {}
7069
}

src/href.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export default class Href {
2626
let parsedBase: HrefContext | null = null;
2727
// try to use `URL`
2828
try {
29+
// prevent Chrome from parsing `new URL('#abc')`
30+
if (baseStr === undefined && hrefStr.startsWith('#')) {
31+
throw 'e';
32+
}
2933
this._url = new URL(hrefStr, baseStr);
3034
} catch (error) {
3135
// with a base

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* Visit https://aka.ms/tsconfig.json to read more about this file */
77
/* Basic Options */
88
// "incremental": true, /* Enable incremental compilation */
9-
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
9+
"target": "ES2019" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
1010
"module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
1111
// "DOM" for TextEncoder, but Node has it too
1212
// "lib": ["ES2020", "DOM"], /* Specify library files to be included in the compilation. */

0 commit comments

Comments
 (0)