Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ jobs:
- run: npm run build --if-present
- run: npm run test

consumer-tests:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 21.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: |
npm ci
npm run build
cd tests/consumers/cjs && npm install && npm run test
cd ../esm && npm install && npm run test
cd ../ts-local && npm install && npm run test

linting:
runs-on: ubuntu-latest
strategy:
Expand Down
6 changes: 0 additions & 6 deletions babel.config.cjs

This file was deleted.

7 changes: 5 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export * from "./src/index";
export * from "./src/Interfaces";
export * from "./src/Config";
export * from "./src/Constants";
export * from "./src/Interfaces";
export * from "./src/Resource";
export * from "./src/Types";
export * from "./src/Api";
109 changes: 33 additions & 76 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"build": "rm -rf ./dist && microbundle",
"test": "jest --runInBand",
"test:dev": "jest --watch",
"test:consumer": "sh scripts/consumer-test.sh",
"lint": "eslint --max-warnings=0 .",
"lint:watch": "esw --watch --color",
"prepare": "husky"
Expand All @@ -32,7 +33,7 @@
"@babel/preset-typescript": "^7.24.7",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"eslint": "^8.57.1",
"fetch-mock": "^9.11.0",
"fetch-mock": "^11.1.4",
"husky": "^9.1.6",
"jest": "^29.7.0",
"microbundle": "^0.15.1",
Expand Down
8 changes: 8 additions & 0 deletions scripts/consumer-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
echo "TESTING!!!"

npm install
npm run build

cd tests/consumers/cjs && npm run test
cd ../esm && npm run test
cd ../ts-local && npm run test
14 changes: 10 additions & 4 deletions src/index.ts → src/Api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Resource from "./Resource";
import { addRequest, addResponse } from "./Config";

export * from "./Config";
import { Resource } from "./Resource";
import { addRequest, addResponse, setConfig, getConfig } from "./Config";

export const interceptors = {
addRequest,
Expand All @@ -26,3 +24,11 @@ export const find = async (url: string) => {
* @returns IQueryable
*/
export const resource = (url: string) => new Resource(url);

export const api = {
find,
resource,
setConfig,
getConfig,
interceptors,
};
2 changes: 1 addition & 1 deletion src/Interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Resource from "./Resource";
import { Resource } from "./Resource";
import { ConditionTypes, MethodType, QueryFunctionType } from "./Types";

export interface IRequest {
Expand Down
4 changes: 1 addition & 3 deletions src/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
SortType,
} from "./Types";

class Resource implements IQueryable {
export class Resource implements IQueryable {
private url: string;
private config: IInternalConfig;
private params: URLSearchParams;
Expand Down Expand Up @@ -652,5 +652,3 @@ class Resource implements IQueryable {
};
}
}

export default Resource;
11 changes: 11 additions & 0 deletions tests/consumers/cjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const api = require("axe-api-client");

const main = async () => {
api.setConfig({
baseURL: "https://axe-api.com",
});
console.log(api.getConfig());
console.log("CJS module tests are succeed!");
};

main();
38 changes: 38 additions & 0 deletions tests/consumers/cjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/consumers/cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "tester",
"version": "1.0.0",
"main": "common.js",
"type": "commonjs",
"scripts": {
"test": "rm -rf node_modules && rm -rf package-lock.json && npm install && node index.js"
},
"dependencies": {
"axe-api-client": "file:../../../"
}
}
11 changes: 11 additions & 0 deletions tests/consumers/cjs/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
rm -rf node_modules
rm -rf package-lock.json

npm unlink axe-api
npm link axe-api

# npm install
pwd
node index.js

npm unlink axe-api
12 changes: 12 additions & 0 deletions tests/consumers/esm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { api } from "axe-api-client";

const main = async () => {
api.setConfig({
baseURL: "https://axe-api.com",
});
console.log(api.getConfig());

console.log("ESM module tests are succeed!");
};

main();
Loading