Skip to content

Commit

Permalink
Merge pull request #97 from justindhillon/test
Browse files Browse the repository at this point in the history
Write new tests
  • Loading branch information
justindhillon authored Apr 24, 2024
2 parents 07e8a27 + 1f1fe22 commit 523906c
Show file tree
Hide file tree
Showing 18 changed files with 3,342 additions and 366 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Total Downloads](https://img.shields.io/npm/dt/link-inspector)](https://www.npmjs.com/package/link-inspector)

<div align="center">
<img height="150px" src="https://github.com/justindhillon/link-inspector/assets/145078271/532b05a6-dd98-48f3-aad1-f469c093752a">
<img height="150px" src="https://raw.githubusercontent.com/justindhillon/link-inspector/test/tests/test-folder/logo.png">

<h1>link-inspector</h1>
<h3>Automatically scan links, files, and directories for broken links.</h3>
Expand Down
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);
});
37 changes: 37 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import linkInspector from "../index";

test('Broken link calls callback', async () => {
const promise1 = new Promise<void>((resolve) => {
const callback = (link: string) => {
expect(link).toBe('https://www.google.com/page-not-found');
resolve();
};

linkInspector("https://www.google.com/page-not-found", callback);
});

const promise2 = new Promise<void>((resolve) => {
const callback = (link: string) => {
expect(link).toBe('https://www.wikipedia.org/page-not-found');
resolve();
};

linkInspector("https://www.wikipedia.org/page-not-found", callback);
});

await promise1;
await promise2;
});

test('Test on real folder', async () => {
const promise = new Promise<void>((resolve) => {
const callback = (link: string) => {
expect(link).toBe('https://www.wikipedia.org/page-not-found');
resolve();
};

linkInspector("tests/test-folder", callback);
});

await promise;
});
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.

Binary file added tests/test-folder/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions tests/test-folder/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bowishadve https://www.google.com/ tribution pendaytive
astrus digikiki quz trudicats alginall shopolized
beatorlds reflupper https://www.wikipedia.org/page-not-found
nucch sa eadicerolawyne antilds ij nessinfulleter
expercity larv posion vikins revotempution norted
https://www.un.org/ sweeds corehooker iwoppion burgination
48 changes: 0 additions & 48 deletions tests/test.ts

This file was deleted.

0 comments on commit 523906c

Please sign in to comment.