From 681e1dabfb21314e6b11a564ed6d3d1fa558dcd7 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Mon, 27 Jul 2020 17:08:54 +0200 Subject: [PATCH] fix: add missing exports and tests for new APIs (#495) 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. --- examples/browser-esmodules/example.js | 20 +++++++++++++- examples/browser-rollup/example-all.js | 3 +++ examples/browser-umd/example.html | 5 ++++ examples/browser-umd/example.js | 15 ++++++++++- examples/browser-webpack/example-all.js | 3 +++ examples/node-commonjs/example.js | 35 +++++++++++++++++++------ examples/node-esmodules/example.mjs | 25 +++++++++++++++++- test/browser/browser.spec.js | 3 +++ wrapper.mjs | 5 ++++ 9 files changed, 103 insertions(+), 11 deletions(-) diff --git a/examples/browser-esmodules/example.js b/examples/browser-esmodules/example.js index efe4e3f6..7b1ac765 100644 --- a/examples/browser-esmodules/example.js +++ b/examples/browser-esmodules/example.js @@ -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'; @@ -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()); @@ -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)); diff --git a/examples/browser-rollup/example-all.js b/examples/browser-rollup/example-all.js index 4e421731..69997651 100644 --- a/examples/browser-rollup/example-all.js +++ b/examples/browser-rollup/example-all.js @@ -1,4 +1,5 @@ import { + NIL as NIL_UUID, parse as uuidParse, stringify as uuidStringify, v1 as uuidv1, @@ -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)); @@ -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)); diff --git a/examples/browser-umd/example.html b/examples/browser-umd/example.html index a509e31f..f1a99b9e 100644 --- a/examples/browser-umd/example.html +++ b/examples/browser-umd/example.html @@ -2,6 +2,11 @@ UUID UMD example

Please open the Developer Console to view output

+ + + + + diff --git a/examples/browser-umd/example.js b/examples/browser-umd/example.js index 81a622cd..ad65cf22 100644 --- a/examples/browser-umd/example.js +++ b/examples/browser-umd/example.js @@ -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()); @@ -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()); @@ -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)); diff --git a/examples/browser-webpack/example-all.js b/examples/browser-webpack/example-all.js index 4e421731..69997651 100644 --- a/examples/browser-webpack/example-all.js +++ b/examples/browser-webpack/example-all.js @@ -1,4 +1,5 @@ import { + NIL as NIL_UUID, parse as uuidParse, stringify as uuidStringify, v1 as uuidv1, @@ -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)); @@ -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)); diff --git a/examples/node-commonjs/example.js b/examples/node-commonjs/example.js index 909042af..6a75f5a1 100644 --- a/examples/node-commonjs/example.js +++ b/examples/node-commonjs/example.js @@ -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)); @@ -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)); @@ -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)); @@ -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); diff --git a/examples/node-esmodules/example.mjs b/examples/node-esmodules/example.mjs index 38221716..a265b459 100644 --- a/examples/node-esmodules/example.mjs +++ b/examples/node-esmodules/example.mjs @@ -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'; @@ -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()); @@ -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); diff --git a/test/browser/browser.spec.js b/test/browser/browser.spec.js index a0d9d543..72a0b7dd 100644 --- a/test/browser/browser.spec.js +++ b/test/browser/browser.spec.js @@ -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'); @@ -32,6 +33,7 @@ const expectations = { 'uuidv5() URL': v5url, 'uuidv5() MY_NAMESPACE': v5custom, + NIL_UUID: nil, 'uuidParse()': parse, 'uuidStringify()': stringify, 'uuidValidate()': validate, @@ -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, diff --git a/wrapper.mjs b/wrapper.mjs index 87e7f2e7..c31e9cef 100644 --- a/wrapper.mjs +++ b/wrapper.mjs @@ -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;