Skip to content

Commit

Permalink
fix: add missing exports and tests for new APIs (#495)
Browse files Browse the repository at this point in the history
The new APIs were still missing from some environment-specific tests. We
should definitely consider consolidating these environment-specific test
cases somehow, this currently requires way too much manual work and it's
too easy to miss certain places that need an update.
  • Loading branch information
ctavan authored Jul 27, 2020
1 parent 8780344 commit 681e1da
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 11 deletions.
20 changes: 19 additions & 1 deletion examples/browser-esmodules/example.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import {
NIL as NIL_UUID,
parse as uuidParse,
stringify as uuidStringify,
v1 as uuidv1,
v4 as uuidv4,
v3 as uuidv3,
v4 as uuidv4,
v5 as uuidv5,
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';

Expand Down Expand Up @@ -36,6 +41,13 @@ 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));

// Utility functions
console.log('NIL_UUID', NIL_UUID);
console.log('uuidParse()', uuidParse(MY_NAMESPACE));
console.log('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
console.log('uuidValidate()', uuidValidate(MY_NAMESPACE));
console.log('uuidVersion()', uuidVersion(MY_NAMESPACE));

console.log('Same with default export');

console.log('uuid.v1()', uuid.v1());
Expand All @@ -46,3 +58,9 @@ console.log('uuid.v3() MY_NAMESPACE', uuid.v3('Hello, World!', MY_NAMESPACE));
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.NIL', uuid.NIL);
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));
3 changes: 3 additions & 0 deletions examples/browser-rollup/example-all.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
NIL as NIL_UUID,
parse as uuidParse,
stringify as uuidStringify,
v1 as uuidv1,
Expand Down Expand Up @@ -46,6 +47,7 @@ testpage(function (addTest, done) {
addTest('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));

// Utility functions
addTest('NIL_UUID', NIL_UUID);
addTest('uuidParse()', uuidParse(MY_NAMESPACE));
addTest('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
addTest('uuidValidate()', uuidValidate(MY_NAMESPACE));
Expand All @@ -62,6 +64,7 @@ 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.NIL', uuid.NIL);
addTest('uuid.parse()', uuid.parse(MY_NAMESPACE));
addTest('uuid.stringify()', uuid.stringify(uuid.parse(MY_NAMESPACE)));
addTest('uuid.validate()', uuid.validate(MY_NAMESPACE));
Expand Down
5 changes: 5 additions & 0 deletions examples/browser-umd/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<title>UUID UMD example</title>
<p>Please open the Developer Console to view output</p>
<script src="./node_modules/uuid/dist/umd/uuid.min.js"></script>
<script src="./node_modules/uuid/dist/umd/uuidNIL.min.js"></script>
<script src="./node_modules/uuid/dist/umd/uuidParse.min.js"></script>
<script src="./node_modules/uuid/dist/umd/uuidStringify.min.js"></script>
<script src="./node_modules/uuid/dist/umd/uuidValidate.min.js"></script>
<script src="./node_modules/uuid/dist/umd/uuidVersion.min.js"></script>
<script src="./node_modules/uuid/dist/umd/uuidv1.min.js"></script>
<script src="./node_modules/uuid/dist/umd/uuidv3.min.js"></script>
<script src="./node_modules/uuid/dist/umd/uuidv4.min.js"></script>
Expand Down
15 changes: 14 additions & 1 deletion examples/browser-umd/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global uuid:false, uuidv1:false, uuidv3:false, uuidv4:false, uuidv5:false */
/* global uuid:false, uuidv1:false, uuidv3:false, uuidv4:false, uuidv5:false, uuidNIL:false, uuidParse:false, uuidStringify:false, uuidValidate:false, uuidVersion:false */
console.log('uuidv1()', uuidv1());

console.log('uuidv4()', uuidv4());
Expand Down Expand Up @@ -29,6 +29,13 @@ 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));

// Utility functions
console.log('NIL_UUID', uuidNIL);
console.log('uuidParse()', uuidParse(MY_NAMESPACE));
console.log('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
console.log('uuidValidate()', uuidValidate(MY_NAMESPACE));
console.log('uuidVersion()', uuidVersion(MY_NAMESPACE));

console.log('Same with default export');

console.log('uuid.v1()', uuid.v1());
Expand All @@ -39,3 +46,9 @@ console.log('uuid.v3() MY_NAMESPACE', uuid.v3('Hello, World!', MY_NAMESPACE));
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.NIL', uuid.NIL);
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));
3 changes: 3 additions & 0 deletions examples/browser-webpack/example-all.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
NIL as NIL_UUID,
parse as uuidParse,
stringify as uuidStringify,
v1 as uuidv1,
Expand Down Expand Up @@ -46,6 +47,7 @@ testpage(function (addTest, done) {
addTest('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));

// Utility functions
addTest('NIL_UUID', NIL_UUID);
addTest('uuidParse()', uuidParse(MY_NAMESPACE));
addTest('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
addTest('uuidValidate()', uuidValidate(MY_NAMESPACE));
Expand All @@ -62,6 +64,7 @@ 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.NIL', uuid.NIL);
addTest('uuid.parse()', uuid.parse(MY_NAMESPACE));
addTest('uuid.stringify()', uuid.stringify(uuid.parse(MY_NAMESPACE)));
addTest('uuid.validate()', uuid.validate(MY_NAMESPACE));
Expand Down
35 changes: 27 additions & 8 deletions examples/node-commonjs/example.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
const { v1: uuidv1 } = require('uuid');
const {
NIL: NIL_UUID,
parse: uuidParse,
stringify: uuidStringify,
v1: uuidv1,
v3: uuidv3,
v4: uuidv4,
v5: uuidv5,
validate: uuidValidate,
version: uuidVersion,
} = require('uuid');
const uuid = require('uuid');
const pkg = require('uuid/package.json');

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

const { v4: uuidv4 } = require('uuid');
console.log('uuidv4()', uuidv4());

const { v3: uuidv3 } = require('uuid');

// ... using predefined DNS namespace (for domain names)
console.log('uuidv3() DNS', uuidv3('hello.example.com', uuidv3.DNS));

Expand All @@ -19,8 +29,6 @@ console.log('uuidv3() URL', uuidv3('http://example.com/hello', uuidv3.URL));
const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c';
console.log('uuidv3() MY_NAMESPACE', uuidv3('Hello, World!', MY_NAMESPACE));

const { v5: uuidv5 } = require('uuid');

// ... using predefined DNS namespace (for domain names)
console.log('uuidv5() DNS', uuidv5('hello.example.com', uuidv5.DNS));

Expand All @@ -34,9 +42,15 @@ 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));

// Utility functions
console.log('NIL_UUID', NIL_UUID);
console.log('uuidParse()', uuidParse(MY_NAMESPACE));
console.log('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
console.log('uuidValidate()', uuidValidate(MY_NAMESPACE));
console.log('uuidVersion()', uuidVersion(MY_NAMESPACE));

console.log('Same with default export');

const uuid = require('uuid');
console.log('uuid.v1()', uuid.v1());
console.log('uuid.v4()', uuid.v4());
console.log('uuid.v3() DNS', uuid.v3('hello.example.com', uuid.v3.DNS));
Expand All @@ -46,6 +60,11 @@ 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.NIL', uuid.NIL);
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
const pkg = require('uuid/package.json');
console.log('pkg.name', pkg.name);
25 changes: 24 additions & 1 deletion examples/node-esmodules/example.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { v1 as uuidv1, v4 as uuidv4, v3 as uuidv3, v5 as uuidv5 } from 'uuid';
import {
NIL as NIL_UUID,
parse as uuidParse,
stringify as uuidStringify,
v1 as uuidv1,
v3 as uuidv3,
v4 as uuidv4,
v5 as uuidv5,
validate as uuidValidate,
version as uuidVersion,
} from 'uuid';
import * as uuid from 'uuid';
import pkg from 'uuid/package.json';

Expand Down Expand Up @@ -32,6 +42,13 @@ 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));

// Utility functions
console.log('NIL_UUID', NIL_UUID);
console.log('uuidParse()', uuidParse(MY_NAMESPACE));
console.log('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
console.log('uuidValidate()', uuidValidate(MY_NAMESPACE));
console.log('uuidVersion()', uuidVersion(MY_NAMESPACE));

console.log('Same with default export');

console.log('uuid.v1()', uuid.v1());
Expand All @@ -43,5 +60,11 @@ 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.NIL', uuid.NIL);
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);
3 changes: 3 additions & 0 deletions test/browser/browser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const v5dns = (result) => expect(result).toBe('fdda765f-fc57-5604-a269-52a7df816
const v5url = (result) => expect(result).toBe('3bbcee75-cecc-5b56-8031-b6641c1ed1f1');
const v5custom = (result) => expect(result).toBe('c49c5142-4d9a-5940-a926-612ede0ec632');

const nil = (result) => expect(result).toBe('00000000-0000-0000-0000-000000000000');
const parse = (result) =>
expect(result).toEqual('85,35,141,21,201,38,69,152,180,157,207,78,145,59,161,60');
const stringify = (result) => expect(result).toBe('55238d15-c926-4598-b49d-cf4e913ba13c');
Expand All @@ -32,6 +33,7 @@ const expectations = {
'uuidv5() URL': v5url,
'uuidv5() MY_NAMESPACE': v5custom,

NIL_UUID: nil,
'uuidParse()': parse,
'uuidStringify()': stringify,
'uuidValidate()': validate,
Expand All @@ -46,6 +48,7 @@ const expectations = {
'uuid.v5() URL': v5url,
'uuid.v5() MY_NAMESPACE': v5custom,

'uuid.NIL': nil,
'uuid.parse()': parse,
'uuid.stringify()': stringify,
'uuid.validate()': validate,
Expand Down
5 changes: 5 additions & 0 deletions wrapper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ export const v1 = uuid.v1;
export const v3 = uuid.v3;
export const v4 = uuid.v4;
export const v5 = uuid.v5;
export const NIL = uuid.NIL;
export const version = uuid.version;
export const validate = uuid.validate;
export const stringify = uuid.stringify;
export const parse = uuid.parse;

0 comments on commit 681e1da

Please sign in to comment.