From 65fc9d5ab76f93e1d7179cd27b3f541125865985 Mon Sep 17 00:00:00 2001 From: Wouter van der Plas <2423856+wvanderp@users.noreply.github.com> Date: Mon, 20 Nov 2023 22:13:13 +0100 Subject: [PATCH] fix tests? --- README.md | 10 +++++----- package-lock.json | 32 -------------------------------- package.json | 2 +- tests/utils/api/getToken.spec.ts | 12 +++++++++++- tsconfig.build.json | 8 +++++--- tsconfig.json | 3 ++- 6 files changed, 24 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 275ef0c..4a5c3df 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ A better way of working with the wikidata ## Features -- work with wikidata using classes -- request items from wikidata -- upload the changes +- Work with wikidata using classes +- Request items from wikidata +- Upload the changes ## Getting Started @@ -19,7 +19,7 @@ A better way of working with the wikidata npm i --save iwf ``` -you can easily request an item from wikidata and list all the labels. +You can easily request an item from wikidata and list all the labels. ```typescript import {requestItem} from 'iwf'; @@ -49,7 +49,7 @@ upload(item, { ## Documentation -To see all the functionality, extra documentation and examples, visit [the documentation](https://wvanderp.github.io/iwf/) +To see all the functionality, extra documentation, and examples, visit [the documentation](https://wvanderp.github.io/iwf/) ## License diff --git a/package-lock.json b/package-lock.json index 6ba5c4f..351cdd9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,8 +20,6 @@ "@babel/preset-env": "^7.23.3", "@babel/preset-typescript": "^7.23.3", "@istanbuljs/nyc-config-typescript": "^1.0.2", - "@types/chai": "^4.3.10", - "@types/chai-as-promised": "^7.1.8", "@types/deep-diff": "^1.0.5", "@types/jest": "^29.5.8", "@types/node": "^20.9.0", @@ -3005,21 +3003,6 @@ "@babel/types": "^7.20.7" } }, - "node_modules/@types/chai": { - "version": "4.3.10", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.10.tgz", - "integrity": "sha512-of+ICnbqjmFCiixUnqRulbylyXQrPqIGf/B3Jax1wIF3DvSheysQxAWvqHhZiW3IQrycvokcLcFQlveGp+vyNg==", - "dev": true - }, - "node_modules/@types/chai-as-promised": { - "version": "7.1.8", - "resolved": "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.8.tgz", - "integrity": "sha512-ThlRVIJhr69FLlh6IctTXFkmhtP3NpMZ2QGq69StYLyKZFp/HOp1VdKZj7RvfNWYYcJ1xlbLGLLWj1UvP5u/Gw==", - "dev": true, - "dependencies": { - "@types/chai": "*" - } - }, "node_modules/@types/deep-diff": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/deep-diff/-/deep-diff-1.0.5.tgz", @@ -13883,21 +13866,6 @@ "@babel/types": "^7.20.7" } }, - "@types/chai": { - "version": "4.3.10", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.10.tgz", - "integrity": "sha512-of+ICnbqjmFCiixUnqRulbylyXQrPqIGf/B3Jax1wIF3DvSheysQxAWvqHhZiW3IQrycvokcLcFQlveGp+vyNg==", - "dev": true - }, - "@types/chai-as-promised": { - "version": "7.1.8", - "resolved": "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.8.tgz", - "integrity": "sha512-ThlRVIJhr69FLlh6IctTXFkmhtP3NpMZ2QGq69StYLyKZFp/HOp1VdKZj7RvfNWYYcJ1xlbLGLLWj1UvP5u/Gw==", - "dev": true, - "requires": { - "@types/chai": "*" - } - }, "@types/deep-diff": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/deep-diff/-/deep-diff-1.0.5.tgz", diff --git a/package.json b/package.json index 1811b99..0dca500 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "eslint": "eslint --ext ts,js src/ tests/ integration/", "prepublish": "npm run build", "test": "jest --testPathIgnorePatterns=\"/integration/\"", - "test:all": "jest", + "test:all": "jest --runInBand", "coverage": "npm run test -- --coverage", "coverage:all": "jest --coverage", "clean": "rimraf lib/ .nyc_output/ coverage/ docs/" diff --git a/tests/utils/api/getToken.spec.ts b/tests/utils/api/getToken.spec.ts index ec62dbc..39797c1 100644 --- a/tests/utils/api/getToken.spec.ts +++ b/tests/utils/api/getToken.spec.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import getToken from '../../../src/utils/api/token'; +import getToken, { loginUrl } from '../../../src/utils/api/token'; jest.mock('axios'); const mockedAxios = axios as jest.Mocked; @@ -30,4 +30,14 @@ describe('getToken', () => { // @ts-expect-error testing await expect(() => getToken('a', 'a', null)).rejects.toThrow(); }); + + it('should return the correct url', () => { + // normal urls + expect(loginUrl('https://www.wikidata.org')).toBe('https://www.wikidata.org/w/api.php?action=login&format=json'); + expect(loginUrl('https://test.wikidata.org')).toBe('https://test.wikidata.org/w/api.php?action=login&format=json'); + + // urls with a path + expect(loginUrl('https://www.wikidata.org/wiki/Main_Page')).toBe('https://www.wikidata.org/w/api.php?action=login&format=json'); + expect(loginUrl('https://test.wikidata.org/wiki/Main_Page')).toBe('https://test.wikidata.org/w/api.php?action=login&format=json'); + }); }); diff --git a/tsconfig.build.json b/tsconfig.build.json index bca5865..a425c20 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -6,12 +6,14 @@ "./nyc_output", "coverage", "diff", - "tests", + "tests/**/*", + "integration/**/*", "./test.ts", "./lib", - "./scrap.ts" + "./scrap*.ts", + "**/*.spec.ts" ], "filesGlob": [ "./src/**/*.ts" ] -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index 4ac8a7a..18722aa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -74,6 +74,7 @@ "diff", "./test.ts", "./lib", - "./scrap.ts" + "./scrap.ts", + "**/*.spec.ts" ] }