Skip to content

Commit f832b87

Browse files
committed
Initial commit.
0 parents  commit f832b87

23 files changed

+7349
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules/
2+
.tmp
3+
.DS_Store
4+
coverage/
5+
.idea
6+
.yarn.lock
7+
/lib/
8+
/es/
9+
/dist/

.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
.tmp
3+
.DS_Store
4+
coverage/
5+
.idea
6+
.yarn.lock
7+
jest/
8+
examples/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Johnny Klironomos
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

babel.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const cjs = process.env.BABEL_ENV === "commonjs";
2+
3+
module.exports = {
4+
presets: [["@babel/env", { modules: false }]],
5+
plugins: [
6+
cjs && "@babel/transform-modules-commonjs",
7+
["@babel/transform-runtime", { useESModules: !cjs }]
8+
].filter(Boolean),
9+
env: {
10+
test: {
11+
presets: [
12+
[
13+
"@babel/env",
14+
{
15+
useBuiltIns: "entry",
16+
targets: {
17+
node: "current"
18+
},
19+
corejs: 3
20+
}
21+
]
22+
],
23+
plugins: ["@babel/transform-runtime"]
24+
}
25+
}
26+
};

jest/config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
rootDir: "../",
3+
testMatch: ["<rootDir>/src/**/*.test.js"],
4+
moduleDirectories: [
5+
"<rootDir>/node_modules",
6+
"./node_modules",
7+
"<rootDir>/jest"
8+
],
9+
setupFiles: ["<rootDir>/jest/setup.js"],
10+
setupFilesAfterEnv: ["<rootDir>/jest/setupForEach.js"],
11+
transformIgnorePatterns: ["node_modules"],
12+
verbose: true,
13+
coverageDirectory: "<rootDir>/coverage",
14+
coveragePathIgnorePatterns: ["/node_modules/", "/jest/"],
15+
coverageThreshold: {
16+
global: {
17+
branches: 100.0,
18+
functions: 100.0
19+
}
20+
},
21+
globals: {}
22+
};

jest/setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global.fetch = require("jest-fetch-mock");

jest/setupForEach.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
afterEach(() => jest.restoreAllMocks());
2+
afterEach(() => jest.clearAllMocks());
3+
afterEach(() => jest.clearAllTimers());

package.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "@workablehr/request",
3+
"description": "Request",
4+
"license": "UNLICENSED",
5+
"version": "0.0.1",
6+
"main": "lib/index.js",
7+
"module": "es/index.js",
8+
"keywords": [
9+
"json:api",
10+
"client",
11+
"serialize",
12+
"deserialize"
13+
],
14+
"files": [
15+
"dist",
16+
"lib",
17+
"src",
18+
"es"
19+
],
20+
"sideEffects": false,
21+
"npmName": "@workablehr/request",
22+
"npmFileMap": [
23+
{
24+
"basePath": "/dist/",
25+
"files": [
26+
"*.js"
27+
]
28+
}
29+
],
30+
"scripts": {
31+
"clean": "rimraf lib dist es coverage",
32+
"build:commonjs": "BABEL_ENV=commonjs babel src --out-dir lib",
33+
"build:es": "babel src --out-dir es",
34+
"build:umd": "webpack",
35+
"build": "yarn build:commonjs && yarn build:es && yarn build:umd",
36+
"test": "jest --config ./jest/config.js",
37+
"prepublishOnly": "yarn clean && yarn build",
38+
"publish:beta": "npm publish --tag=next",
39+
"docs": "jsdoc -c doc.conf.json"
40+
},
41+
"dependencies": {
42+
"@babel/runtime": "7.8.3",
43+
"@workablehr/idb": "^0.0.1"
44+
},
45+
"devDependencies": {
46+
"@babel/cli": "7.8.3",
47+
"@babel/core": "7.8.3",
48+
"@babel/plugin-transform-modules-commonjs": "7.8.3",
49+
"@babel/plugin-transform-runtime": "7.8.3",
50+
"@babel/preset-env": "7.8.3",
51+
"babel-jest": "25.1.0",
52+
"babel-loader": "8.0.6",
53+
"core-js": "3.6.4",
54+
"docdash": "1.1.1",
55+
"jest": "25.1.0",
56+
"jest-fetch-mock": "2.1.2",
57+
"node-fetch": "2.6.0",
58+
"webpack": "4.41.5",
59+
"webpack-cli": "3.3.10",
60+
"whatwg-fetch": "3.0.0"
61+
}
62+
}

src/getAbortController/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const noop = () => {};
2+
3+
export default () => {
4+
if (!window.AbortController) return { signal: {}, abort: noop };
5+
6+
const controller = new AbortController();
7+
const abort = () => {
8+
try {
9+
controller.abort();
10+
return "aborted";
11+
} catch (e) {
12+
return e;
13+
}
14+
};
15+
return {
16+
signal: controller.signal,
17+
abort
18+
};
19+
};

src/getAbortController/index.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import getAbortController from "./index";
2+
3+
it("has AbortSignal and abort function", () => {
4+
const { signal, abort } = getAbortController();
5+
expect(signal).toBeInstanceOf(AbortSignal);
6+
expect(typeof abort === "function").toBeTruthy();
7+
expect(signal.aborted).toBeFalsy();
8+
});
9+
10+
it("has default empty signal and noop abort", () => {
11+
const realAbortController = global.AbortController;
12+
global.AbortController = null;
13+
const { signal, abort } = getAbortController();
14+
expect(signal).not.toBeInstanceOf(AbortSignal);
15+
expect(signal).toEqual({});
16+
expect(typeof abort === "function").toBeTruthy();
17+
expect(signal.aborted).toBeUndefined();
18+
expect(abort()).toBeUndefined();
19+
global.AbortController = realAbortController;
20+
});
21+
22+
it("doesn't throw on abort errors", () => {
23+
const { abort: abortSuccess, signal: signalSuccess } = getAbortController();
24+
expect(abortSuccess()).toBe("aborted");
25+
expect(signalSuccess.aborted).toBeTruthy();
26+
const realAbortController = global.AbortController;
27+
global.AbortController = function() {
28+
return {
29+
signal: { aborted: false },
30+
abort: jest.fn(() => {
31+
throw "Abort throws";
32+
})
33+
};
34+
};
35+
const { abort: abortFail, signal: signalFail } = getAbortController();
36+
expect(abortFail()).toBe("Abort throws");
37+
expect(signalFail.aborted).toBeFalsy();
38+
global.AbortController = realAbortController;
39+
});

0 commit comments

Comments
 (0)