Skip to content

Commit

Permalink
checkLink.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
justindhillon committed Apr 9, 2024
1 parent 07e8a27 commit 6de7cde
Show file tree
Hide file tree
Showing 14 changed files with 3,298 additions and 365 deletions.
2 changes: 2 additions & 0 deletions checkLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const ignoredCodes: Set<number> = new Set([
]);

const ignoredURLs: Set<string> = new Set([
'localhost',
'127.0.0.1',
'example.com',
'www.example.com',
'example.org',
Expand Down
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
3,536 changes: 3,250 additions & 286 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"author": "Justin Dhillon",
"license": "AGPL-3.0-or-later",
"description": "NPM Tool That Audits Projects For Broken Links",

"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
Expand All @@ -14,7 +13,6 @@
"files": [
"!**/*"
],

"repository": {
"type": "git",
"url": "git+https://github.com/justindhillon/link-inspector.git"
Expand All @@ -30,14 +28,15 @@
"url": "https://github.com/justindhillon/link-inspector/issues"
},
"homepage": "https://github.com/justindhillon/link-inspector#readme",

"scripts": {
"build": "tsup index.ts --format cjs,esm --dts --minify && tsup bin.ts --minify",
"lint": "tsc",
"test": "ts-node tests/test.ts"
"test": "jest"
},
"devDependencies": {
"ts-node": "^10.9.2",
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"ts-jest": "^29.1.2",
"tsup": "^8.0.1",
"typescript": "^5.3.3"
},
Expand Down
37 changes: 37 additions & 0 deletions tests/checkLink.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { checkLink } from "../checkLink";

test('api. returns false', async () => {
expect(await checkLink("https://api.pythagora.io/telemetry")).toBe(false);
});

test('localhost returns false', async () => {
expect(await checkLink("https://localhost/")).toBe(false);
expect(await checkLink("https://127.0.0.1/")).toBe(false);
});

test('White Listed URLS return false', async () => {
expect(await checkLink("https://www.google.com/")).toBe(false);
expect(await checkLink("https://example.com/")).toBe(false);
expect(await checkLink("https://www.example.com/")).toBe(false);
expect(await checkLink("https://example.org/")).toBe(false);
expect(await checkLink("https://www.example.org/")).toBe(false);
expect(await checkLink("https://goo.gl/")).toBe(false);
expect(await checkLink("https://fonts.googleapis.com")).toBe(false);
expect(await checkLink("https://fonts.gstatic.com")).toBe(false);
});

test('Valid Links return false', async () => {
expect(await checkLink("https://www.google.com/")).toBe(false);
expect(await checkLink("https://www.wikipedia.org/")).toBe(false);
expect(await checkLink("https://www.nasa.gov/")).toBe(false);
expect(await checkLink("https://www.bbc.com/")).toBe(false);
expect(await checkLink("https://www.un.org/")).toBe(false);
});

test('Broken Links return true', async () => {
expect(await checkLink("https://www.google.com/page-not-found")).toBe(true);
expect(await checkLink("https://www.wikipedia.org/page-not-found")).toBe(true);
expect(await checkLink("https://www.nasa.gov/page-not-found")).toBe(true);
expect(await checkLink("https://www.bbc.com/page-not-found")).toBe(true);
expect(await checkLink("https://www.un.org/page-not-found")).toBe(true);
});
5 changes: 0 additions & 5 deletions tests/links/brokenLinks

This file was deleted.

3 changes: 0 additions & 3 deletions tests/links/falsePositive

This file was deleted.

Binary file removed tests/links/skip.png
Binary file not shown.
5 changes: 0 additions & 5 deletions tests/links/subfolder/brokenLinks

This file was deleted.

3 changes: 0 additions & 3 deletions tests/links/subfolder/falsePositive

This file was deleted.

Binary file removed tests/links/subfolder/skip.png
Binary file not shown.
5 changes: 0 additions & 5 deletions tests/links/subfolder/workingLinks

This file was deleted.

5 changes: 0 additions & 5 deletions tests/links/workingLinks

This file was deleted.

48 changes: 0 additions & 48 deletions tests/test.ts

This file was deleted.

0 comments on commit 6de7cde

Please sign in to comment.