Skip to content

Commit

Permalink
refactor: inline the test sink
Browse files Browse the repository at this point in the history
We're the only ones using it
  • Loading branch information
wkillerud committed Aug 19, 2024
1 parent 5bca603 commit 7fc0103
Show file tree
Hide file tree
Showing 18 changed files with 372 additions and 18 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"start": "node ./bin/eik-server.js | pino-pretty",
"test": "cross-env LOG_LEVEL=fatal tap ./test --disable-coverage --allow-empty-coverage",
"test:ci": "cross-env LOG_LEVEL=trace tap ./test --disable-coverage --allow-empty-coverage",
"test:snapshots": "cross-env LOG_LEVEL=fatal tap --snapshot --disable-coverage --allow-empty-coverage",
"test": "cross-env LOG_LEVEL=fatal npm run test:tap",
"test:ci": "cross-env LOG_LEVEL=trace npm run test:tap",
"test:snapshots": "cross-env LOG_LEVEL=fatal npm run test:tap -- --snapshot",
"test:tap": "tap ./test/**/*.test.js --disable-coverage --allow-empty-coverage",
"types": "run-s types:module types:test",
"types:module": "tsc",
"types:test": "tsc --project tsconfig.test.json"
Expand Down Expand Up @@ -58,6 +59,7 @@
"@eik/prettier-config": "1.0.1",
"@eik/semantic-release-config": "1.0.0",
"@eik/typescript-config": "1.0.0",
"@types/mime": "3.0.4",
"cross-env": "7.0.3",
"eslint": "9.8.0",
"form-data": "4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion test/400.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tap from 'tap';
import url from 'url';
import fs from 'fs';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion test/404.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fastify from 'fastify';
import fetch from 'node-fetch';
import tap from 'tap';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

/** @type {import('fastify').FastifyInstance} */
Expand Down
2 changes: 1 addition & 1 deletion test/alias.map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tap from 'tap';
import url from 'url';
import fs from 'fs';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion test/alias.npm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tap from 'tap';
import url from 'url';
import fs from 'fs';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion test/alias.pkg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tap from 'tap';
import url from 'url';
import fs from 'fs';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion test/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fastify from 'fastify';
import fetch from 'node-fetch';
import tap from 'tap';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

/** @type {import('fastify').FastifyInstance} */
Expand Down
2 changes: 1 addition & 1 deletion test/http.cache.control.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tap from 'tap';
import url from 'url';
import fs from 'fs';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion test/http.etag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fastify from 'fastify';
import fetch from 'node-fetch';
import tap from 'tap';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

/** @type {import('fastify').FastifyInstance} */
Expand Down
2 changes: 1 addition & 1 deletion test/http.override.cache.control.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tap from 'tap';
import url from 'url';
import fs from 'fs';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion test/http.query.params.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tap from 'tap';
import url from 'url';
import fs from 'fs';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion test/img.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tap from 'tap';
import url from 'url';
import fs from 'fs';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion test/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tap from 'tap';
import url from 'url';
import fs from 'fs';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion test/npm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tap from 'tap';
import url from 'url';
import fs from 'fs';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion test/pkg-put-write-integrity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tap from 'tap';
import url from 'url';
import fs from 'fs';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion test/pkg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tap from 'tap';
import url from 'url';
import fs from 'fs';

import Sink from '@eik/core/lib/sinks/test.js';
import Sink from './utils/sink.js';
import Server from '../lib/main.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand Down
35 changes: 35 additions & 0 deletions test/utils/mem-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import crypto from 'node:crypto';

const Entry = class Entry {
constructor({ mimeType = 'application/octet-stream', payload = [] } = {}) {
this._mimeType = mimeType;
this._payload = payload;
this._hash = '';

if (Array.isArray(payload)) {
const hash = crypto.createHash('sha512');
payload.forEach((buffer) => {
hash.update(buffer.toString());
});
this._hash = `sha512-${hash.digest('base64')}`;
}
}

get mimeType() {
return this._mimeType;
}

get payload() {
return this._payload;
}

get hash() {
return this._hash;
}

get [Symbol.toStringTag]() {
return 'Entry';
}
};

export default Entry;
Loading

0 comments on commit 7fc0103

Please sign in to comment.