Skip to content

Commit

Permalink
fix: esmodule examples
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa committed Aug 8, 2024
1 parent 4d20061 commit 27b0988
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 25 deletions.
5 changes: 4 additions & 1 deletion examples/browser-esmodules/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import {
// Import attribute syntax is still awaiting finalization. In the meantime we
// use dynamic import to allows to specifyg both "assert" and "with" clauses.
// See https://github.com/tc39/proposal-import-attributes
const pkg = await import('uuid/package.json', { assert: { type: 'json' }, with: { type: 'json' } });
const pkg = await import('./node_modules/uuid/package.json', {
assert: { type: 'json' },
with: { type: 'json' },
});

console.log('pkg', pkg);

Expand Down
12 changes: 6 additions & 6 deletions examples/browser-esmodules/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/node-esmodules/example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ console.log('uuid.validate()', uuid.validate(MY_NAMESPACE));
console.log('uuid.version()', uuid.version(MY_NAMESPACE));

// Some tools like react-native need to introspect the package.json file
console.log('pkg.name', pkg.name);
console.log('pkg.name', pkg.default.name);
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
"test:browser": "wdio run ./wdio.conf.js",
"test:node": "npm-run-all --parallel examples:node:**",
"test:pack": "./scripts/testpack.sh",
"test:watch": "node --test --enable-source-maps --watch dist/esm/test/*.test.js",
"test": "node --test --enable-source-maps dist/esm/test/*.test.js"
"test:watch": "node --test --enable-source-maps --watch dist/esm/test",
"test": "node --test --enable-source-maps dist/esm/test"
},
"repository": {
"type": "git",
Expand Down
1 change: 0 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ for MODULE_TYPE in esm cjs; do
cd ${BROWSER_DIR}

for FILE in *-browser*;do
echo "mv $FILE ${FILE/-browser/}"
mv $FILE ${FILE/-browser/}
done
)
Expand Down
14 changes: 0 additions & 14 deletions src/test/v35.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as assert from 'assert';
import test, { describe } from 'node:test';
import md5Browser from '../md5-browser.js';
import md5 from '../md5.js';
import sha1Browser from '../sha1-browser.js';
import sha1 from '../sha1.js';
import v3 from '../v3.js';
import { stringToBytes } from '../v35.js';
Expand Down Expand Up @@ -49,24 +47,12 @@ describe('v35', () => {
});
});

HASH_SAMPLES.forEach(function (sample, i) {
test(`sha1(browser) HASH_SAMPLES[${i}]`, () => {
assert.equal(hashToHex(sha1Browser(sample.input)), sample.sha1);
});
});

HASH_SAMPLES.forEach(function (sample, i) {
test(`md5(node) HASH_SAMPLES[${i}]`, () => {
assert.equal(hashToHex(md5(sample.input)), sample.md5);
});
});

HASH_SAMPLES.forEach(function (sample, i) {
test(`md5(browser) (HASH_SAMPLES[${i}])`, () => {
assert.equal(hashToHex(md5Browser(sample.input) as unknown as Uint8Array), sample.md5);
});
});

test('v3', () => {
// Expect to get the same results as http://tools.adjet.org/uuid-v3
assert.strictEqual(v3('hello.example.com', v3.DNS), '9125a8dc-52ee-365b-a5aa-81b0b3681cf6');
Expand Down

0 comments on commit 27b0988

Please sign in to comment.