mirror of
https://github.com/modernweb-dev/rocket.git
synced 2026-03-10 08:51:24 +00:00
chore: fully typed
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { expect } from 'chai';
|
||||
import { expect } from 'chai';
|
||||
import { HtmlPage, AssetManager } from '../src/index.js';
|
||||
|
||||
const testOptions = {
|
||||
@@ -9,7 +9,9 @@ const testOptions = {
|
||||
describe('Asset', () => {
|
||||
it('01: add local file via file url exists', async () => {
|
||||
const assets = new AssetManager(testOptions);
|
||||
const asset = assets.addExistingFile(new URL('fixtures/01-AssetManager/file.txt', import.meta.url));
|
||||
const asset = assets.addExistingFile(
|
||||
new URL('fixtures/01-AssetManager/file.txt', import.meta.url),
|
||||
);
|
||||
expect(await asset.exists()).to.be.true;
|
||||
});
|
||||
|
||||
@@ -22,13 +24,17 @@ describe('Asset', () => {
|
||||
|
||||
it('01c: local file missing', async () => {
|
||||
const assets = new AssetManager(testOptions);
|
||||
const asset = assets.addUrl(new URL('https://example.com/fixtures/01-AssetManager/missing.txt'));
|
||||
const asset = assets.addUrl(
|
||||
new URL('https://example.com/fixtures/01-AssetManager/missing.txt'),
|
||||
);
|
||||
expect(await asset.exists()).to.be.false;
|
||||
});
|
||||
|
||||
it('01d: local html page exists', async () => {
|
||||
const assets = new AssetManager(testOptions);
|
||||
const page = assets.addExistingFile(new URL('fixtures/01-AssetManager/page.html', import.meta.url));
|
||||
const page = assets.addExistingFile(
|
||||
new URL('fixtures/01-AssetManager/page.html', import.meta.url),
|
||||
);
|
||||
expect(page).to.be.an.instanceOf(HtmlPage);
|
||||
expect(await page.exists()).to.be.true;
|
||||
});
|
||||
@@ -41,7 +47,9 @@ describe('Asset', () => {
|
||||
|
||||
it('03: adds assets while parsing local pages', async () => {
|
||||
const assets = new AssetManager(testOptions);
|
||||
const page = assets.addExistingFile(new URL('fixtures/01-AssetManager/page.html', import.meta.url));
|
||||
const page = /** @type {HtmlPage} */ (
|
||||
assets.addExistingFile(new URL('fixtures/01-AssetManager/page.html', import.meta.url))
|
||||
);
|
||||
await page.parse();
|
||||
expect(assets.size).to.equal(2);
|
||||
});
|
||||
|
||||
@@ -26,6 +26,9 @@ class MockedFetch {
|
||||
return () => Promise.resolve({ ok: true, body: this.stream });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} chunk
|
||||
*/
|
||||
push(chunk) {
|
||||
return this.stream.push(chunk);
|
||||
}
|
||||
@@ -35,6 +38,9 @@ const { expect } = chai;
|
||||
|
||||
const currentDir = path.dirname(new URL(import.meta.url).pathname);
|
||||
|
||||
/**
|
||||
* @param {HtmlPage} page
|
||||
*/
|
||||
function cleanup(page) {
|
||||
const keep = {};
|
||||
keep.hashes = page.hashes;
|
||||
@@ -57,6 +63,9 @@ function cleanup(page) {
|
||||
return keep;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('../types/main.js').HtmlPageOptions} options
|
||||
*/
|
||||
function withTestOptions(options) {
|
||||
return {
|
||||
originUrl: 'https://example.com/',
|
||||
@@ -98,11 +107,13 @@ describe('HtmlPage', () => {
|
||||
|
||||
it.skip('01a: fetch it as an external url', async () => {
|
||||
const mocked = new MockedFetch({
|
||||
// @ts-ignore
|
||||
content: await readFile(new URL('fixtures/01-HtmlPage/01-hashes.html', import.meta.url)),
|
||||
});
|
||||
const page = new HtmlPage(
|
||||
new URL('https://is.mocked.com/'),
|
||||
withTestOptions({
|
||||
// @ts-ignore
|
||||
fetch: mocked.fetch,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -3,6 +3,10 @@ import path from 'path';
|
||||
import { gatherFiles } from '../src/helpers/gatherFiles.js';
|
||||
|
||||
const currentDir = path.dirname(new URL(import.meta.url).pathname);
|
||||
|
||||
/**
|
||||
* @param {string[]} files
|
||||
*/
|
||||
function cleanupFiles(files) {
|
||||
return files.map(file => (file ? `abs::${path.relative(currentDir, file)}` : file));
|
||||
}
|
||||
|
||||
@@ -5,7 +5,15 @@ import { CheckWebsiteCli } from 'check-website';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} rawInputDir
|
||||
* @param {import('../types/main.js').CheckWebsiteCliOptions} options
|
||||
* @param {{ captureLogs?: boolean }} testOptions
|
||||
* @returns
|
||||
*/
|
||||
export async function setupTestCli(rawInputDir, options = {}, testOptions = {}) {
|
||||
/** @type {string[]} */
|
||||
const capturedLogs = [];
|
||||
const origLog = console.log;
|
||||
const origError = console.error;
|
||||
@@ -24,10 +32,10 @@ export async function setupTestCli(rawInputDir, options = {}, testOptions = {})
|
||||
capturedLogs.push(msg);
|
||||
};
|
||||
process.stderr.getWindowSize = () => [80, 24];
|
||||
process.stderr.moveCursor = () => {};
|
||||
process.stderr.cursorTo = () => {};
|
||||
process.stderr.clearLine = () => {};
|
||||
process.stderr.clearScreenDown = () => {};
|
||||
process.stderr.moveCursor = () => true;
|
||||
process.stderr.cursorTo = () => true;
|
||||
process.stderr.clearLine = () => true;
|
||||
process.stderr.clearScreenDown = () => true;
|
||||
}
|
||||
|
||||
const cli = new CheckWebsiteCli();
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
"emitDeclarationOnly": true,
|
||||
"moduleResolution": "NodeNext"
|
||||
},
|
||||
"include": ["src", "types"],
|
||||
"include": ["src", "test-node", "types"],
|
||||
"exclude": ["dist-types"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user