Skip to content

Commit

Permalink
Updated test, bugfix for random no output error
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Oct 5, 2022
1 parent 0b4bfc8 commit c239c3b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default (
namespace: '@exact-realty/esbuild-plugin-inline-js/loader',
},
async ({ path }) => {
const outfile = randomBytes(9).toString('base64');
const outfile = randomBytes(9).toString('base64url');
const result = await esbuild.build({
...config,
entryPoints: [path],
Expand Down
6 changes: 5 additions & 1 deletion test/esbuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import assert from 'node:assert/strict';

describe('Test', () => {
describe('Import results in the right values', () => {
for (const test of ['test-simple', 'test-default-import', 'test-path-import']) {
for (const test of [
'test-simple',
'test-default-import',
'test-path-import',
]) {
it(test, async () => {
await esbuild
.build({
Expand Down
31 changes: 30 additions & 1 deletion test/external.inline.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
(function () {
return 'Hello, World!';
const list = [
'H',
'e',
'l',
'l',
'o',
',',
' ',
'W',
'o',
'r',
'l',
'd',
'!',
];
return list
.map(
(c) => [c.toLowerCase(), c.toUpperCase()].find((d) => d !== c) ?? c,
)
.map((c) => String.prototype.codePointAt.call(c, 0))
.map((c) => c << 1)
.map((c) => c << 1)
.map((c) => c << 1)
.map((c) => c >> 3)
.map((c) => String.fromCodePoint(c))
.map(
(c) => [c.toLowerCase(), c.toUpperCase()].find((d) => d !== c) ?? c,
)
.join(';')
.replace(/;/g, '');
})();
10 changes: 9 additions & 1 deletion test/test-path-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
import { join } from 'node:path';
import { readFileSync } from 'node:fs';

import * as x from './external.inline.ts';

Expand All @@ -29,6 +31,12 @@ assert.equal(
);
assert.equal(new Function('return ' + x.default)(), 'Hello, World!');
assert.equal(
x.path.replace(/external-[^.]+\.js$/, 'external.js'),
x.path.replace(/\/(external)-[^.]+\.js$/, '/$1.js'),
'http://invalid/assets/external.js',
);

const content = readFileSync(join(__dirname, x.path.split('/').pop()));
assert.equal(
x.sri,
'sha384-' + createHash('sha384').update(content).digest('base64'),
);
9 changes: 9 additions & 0 deletions test/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ declare module '*.inline.ts' {

export default content;
}

declare module '*.inline.js' {
const content: string;
export const contentBase64: string;
export const path: string;
export const sri: string;

export default content;
}

0 comments on commit c239c3b

Please sign in to comment.