Skip to content

Commit

Permalink
test: add v1<->v6 utilities to browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa committed Jun 4, 2024
1 parent 8aeee27 commit 6eebe89
Show file tree
Hide file tree
Showing 24 changed files with 14,930 additions and 8,710 deletions.
1 change: 1 addition & 0 deletions .local/uuid/v1tov6.js
1 change: 1 addition & 0 deletions .local/uuid/v6tov1.js
16 changes: 16 additions & 0 deletions bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
"path": "./examples/browser-rollup/dist/v5-size.js",
"maxSize": "1.5 kB"
},
{
"path": "./examples/browser-rollup/dist/v1ToV6-size.js",
"maxSize": "0 kB"
},
{
"path": "./examples/browser-rollup/dist/v6ToV1-size.js",
"maxSize": "0 kB"
},
{ "path": "./examples/browser-rollup/dist/v7-size.js", "maxSize": "0.8 kB" },

{
Expand All @@ -38,6 +46,14 @@
"path": "./examples/browser-webpack/dist/v5-size.js",
"maxSize": "1.5 kB"
},
{
"path": "./examples/browser-webpack/dist/v1ToV6-size.js",
"maxSize": "0.5 kB"
},
{
"path": "./examples/browser-webpack/dist/v6ToV1-size.js",
"maxSize": "0 kB"
},
{ "path": "./examples/browser-webpack/dist/v7-size.js", "maxSize": "0.8 kB" }
]
}
28 changes: 28 additions & 0 deletions examples/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,38 @@ export default function benchmark(uuid, Benchmark) {
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'));
console.log('---\n');
})
.run();
}

function testV6Conversion() {
const suite = new Benchmark.Suite({
onError(event) {
console.error(event.target.error);
},
});

const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';

suite
.add('uuid.v1ToV6()', function () {
uuid.v1ToV6(V1_ID);
})
.add('uuid.v1ToV6() w/ randomization', function () {
uuid.v1ToV6(V1_ID, true);
})
.add('uuid.v6ToV1()', function () {
uuid.v6ToV1(V6_ID);
})
.on('cycle', function (event) {
console.log(event.target.toString());
})
.run();
}

testParseAndStringify();
testGeneration();
testV6Conversion();
}
14 changes: 14 additions & 0 deletions examples/benchmark/package-lock.json

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

23 changes: 19 additions & 4 deletions examples/browser-esmodules/example.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import pkg from 'uuid/package.json';
import * as uuid from './node_modules/uuid/dist/esm-browser/index.js';
import {
NIL as NIL_UUID,
MAX as MAX_UUID,
NIL as NIL_UUID,
parse as uuidParse,
stringify as uuidStringify,
validate as uuidValidate,
version as uuidVersion,
v1 as uuidv1,
v1ToV6 as uuidv1ToV6,
v3 as uuidv3,
v4 as uuidv4,
v5 as uuidv5,
v6ToV1 as uuidv6ToV1,
v7 as uuidv7,
validate as uuidValidate,
version as uuidVersion,
} from './node_modules/uuid/dist/esm-browser/index.js';
import * as uuid from './node_modules/uuid/dist/esm-browser/index.js';

console.log('uuidv1()', uuidv1());

Expand Down Expand Up @@ -45,6 +48,12 @@ console.log('uuidv5() URL', uuidv5('http://example.com/hello', uuidv5.URL));
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
console.log('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));

// v6 <-> v1 conversion
const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
console.log('uuidv1ToV6()', uuidv1ToV6(V1_ID));
console.log('uuidv6ToV1()', uuidv6ToV1(V6_ID));

// Utility functions
console.log('NIL_UUID', NIL_UUID);
console.log('MAX_UUID', MAX_UUID);
Expand All @@ -65,9 +74,15 @@ console.log('uuid.v5() DNS', uuid.v5('hello.example.com', uuid.v5.DNS));
console.log('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
console.log('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));

console.log('uuid.v1ToV6()', uuid.v1ToV6(V1_ID));
console.log('uuid.v6ToV1()', uuid.v6ToV1(V6_ID));

console.log('uuid.NIL', uuid.NIL);
console.log('uuid.MAX', uuid.MAX);
console.log('uuid.parse()', uuid.parse(MY_NAMESPACE));
console.log('uuid.stringify()', uuid.stringify(uuid.parse(MY_NAMESPACE)));
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);
19 changes: 15 additions & 4 deletions examples/browser-rollup/example-all.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import * as uuid from 'uuid';
import {
NIL as NIL_UUID,
MAX as MAX_UUID,
NIL as NIL_UUID,
parse as uuidParse,
stringify as uuidStringify,
validate as uuidValidate,
version as uuidVersion,
v1 as uuidv1,
v1ToV6 as uuidv1ToV6,
v3 as uuidv3,
v4 as uuidv4,
v5 as uuidv5,
v6ToV1 as uuidv6ToV1,
v7 as uuidv7,
validate as uuidValidate,
version as uuidVersion,
} from 'uuid';
import * as uuid from 'uuid';

import testpage from '../utils/testpage';

Expand Down Expand Up @@ -50,6 +52,12 @@ testpage(function (addTest, done) {
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
addTest('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));

// v6 <-> v1 conversion
const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
addTest('uuidv1ToV6()', uuidv1ToV6(V1_ID));
addTest('uuidv6ToV1()', uuidv6ToV1(V6_ID));

// Utility functions
addTest('NIL_UUID', NIL_UUID);
addTest('MAX_UUID', MAX_UUID);
Expand All @@ -70,6 +78,9 @@ testpage(function (addTest, done) {
addTest('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
addTest('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));

addTest('uuid.v1ToV6()', uuid.v1ToV6(V1_ID));
addTest('uuid.v6ToV1()', uuid.v6ToV1(V6_ID));

addTest('uuid.NIL', uuid.NIL);
addTest('uuid.MAX', uuid.MAX);
addTest('uuid.parse()', uuid.parse(MY_NAMESPACE));
Expand Down
14 changes: 14 additions & 0 deletions examples/browser-rollup/package-lock.json

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

11 changes: 11 additions & 0 deletions examples/browser-webpack/example-all-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const {
parse: uuidParse,
stringify: uuidStringify,
v1: uuidv1,
v1ToV6: uuidv1ToV6,
v3: uuidv3,
v4: uuidv4,
v5: uuidv5,
v6ToV1: uuidv6ToV1,
v7: uuidv7,
validate: uuidValidate,
version: uuidVersion,
Expand Down Expand Up @@ -43,6 +45,12 @@ testpage(function (addTest, done) {
// ... using predefined URL namespace (for, well, URLs)
addTest('uuidv5() URL', uuidv5('http://example.com/hello', uuidv5.URL));

// v6 <-> v1 conversion
const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
addTest('uuidv1ToV6()', uuidv1ToV6(V1_ID));
addTest('uuidv6ToV1()', uuidv6ToV1(V6_ID));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
Expand Down Expand Up @@ -70,6 +78,9 @@ testpage(function (addTest, done) {
addTest('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
addTest('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));

addTest('uuid.v1ToV6()', uuid.v1ToV6(V1_ID));
addTest('uuid.v6ToV1()', uuid.v6ToV1(V6_ID));

addTest('uuid.NIL', uuid.NIL);
addTest('uuid.MAX', uuid.MAX);
addTest('uuid.parse()', uuid.parse(MY_NAMESPACE));
Expand Down
19 changes: 15 additions & 4 deletions examples/browser-webpack/example-all.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import * as uuid from 'uuid';
import {
NIL as NIL_UUID,
MAX as MAX_UUID,
NIL as NIL_UUID,
parse as uuidParse,
stringify as uuidStringify,
validate as uuidValidate,
version as uuidVersion,
v1 as uuidv1,
v1ToV6 as uuidv1ToV6,
v3 as uuidv3,
v4 as uuidv4,
v5 as uuidv5,
v6ToV1 as uuidv6ToV1,
v7 as uuidv7,
validate as uuidValidate,
version as uuidVersion,
} from 'uuid';
import * as uuid from 'uuid';

import testpage from '../utils/testpage';

Expand Down Expand Up @@ -50,6 +52,12 @@ testpage(function (addTest, done) {
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
addTest('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));

// v6 <-> v1 conversion
const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
addTest('uuidv1ToV6()', uuidv1ToV6(V1_ID));
addTest('uuidv6ToV1()', uuidv6ToV1(V6_ID));

// Utility functions
addTest('NIL_UUID', NIL_UUID);
addTest('MAX_UUID', MAX_UUID);
Expand All @@ -70,6 +78,9 @@ testpage(function (addTest, done) {
addTest('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
addTest('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));

addTest('uuid.v1ToV6()', uuid.v1ToV6(V1_ID));
addTest('uuid.v6ToV1()', uuid.v6ToV1(V6_ID));

addTest('uuid.NIL', uuid.NIL);
addTest('uuid.MAX', uuid.MAX);
addTest('uuid.parse()', uuid.parse(MY_NAMESPACE));
Expand Down
14 changes: 14 additions & 0 deletions examples/browser-webpack/package-lock.json

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

11 changes: 11 additions & 0 deletions examples/node-commonjs/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ const {
parse: uuidParse,
stringify: uuidStringify,
v1: uuidv1,
v1ToV6: uuidv1ToV6,
v3: uuidv3,
v4: uuidv4,
v5: uuidv5,
v6ToV1: uuidv6ToV1,
v7: uuidv7,
validate: uuidValidate,
version: uuidVersion,
Expand Down Expand Up @@ -46,6 +48,12 @@ console.log('uuidv5() URL', uuidv5('http://example.com/hello', uuidv5.URL));
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
console.log('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));

// v6 <-> v1 conversion
const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
console.log('uuidv1ToV6()', uuidv1ToV6(V1_ID));
console.log('uuidv6ToV1()', uuidv6ToV1(V6_ID));

// Utility functions
console.log('NIL_UUID', NIL_UUID);
console.log('MAX_UUID', MAX_UUID);
Expand All @@ -66,6 +74,9 @@ console.log('uuid.v5() DNS', uuid.v5('hello.example.com', uuid.v5.DNS));
console.log('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
console.log('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));

console.log('uuid.v1ToV6()', uuid.v1ToV6(V1_ID));
console.log('uuid.v6ToV1()', uuid.v6ToV1(V6_ID));

console.log('uuid.NIL', uuid.NIL);
console.log('uuid.MAX', uuid.MAX);
console.log('uuid.parse()', uuid.parse(MY_NAMESPACE));
Expand Down
Loading

0 comments on commit 6eebe89

Please sign in to comment.