index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {assert} from 'chai';
  2. import {machineId, machineIdSync} from '../dist/index';
  3. let {platform} = process,
  4. originalPattern = {
  5. darwin: /^[0-9,A-z]{8}-[0-9,A-z]{4}-[0-9,A-z]{4}-[0-9,A-z]{4}-[0-9,A-z]{12}$/,
  6. win32: /^[0-9,A-z]{8}-[0-9,A-z]{4}-[0-9,A-z]{4}-[0-9,A-z]{4}-[0-9,A-z]{12}$/,
  7. linux: /^[0-9,A-z]{32}$/,
  8. freebsd: /^[0-9,A-z]{8}-[0-9,A-z]{4}-[0-9,A-z]{4}-[0-9,A-z]{4}-[0-9,A-z]{12}$/
  9. },
  10. hashPattern = /^[0-9,A-z]{64}$/;
  11. describe('Async call: machineId({original: true})', function() {
  12. it('should return original unique id', async () => {
  13. let id = await machineId({original: true});
  14. assert.match(id, originalPattern[platform]);
  15. });
  16. });
  17. describe('Sync call: machineIdSync({original: true})', function() {
  18. it('should return original unique id', () => {
  19. assert.match(machineIdSync({original: true}), originalPattern[platform]);
  20. });
  21. });
  22. describe('Async call: machineId()', function() {
  23. it('should return unique sha256-hash', async () => {
  24. let id = await machineId();
  25. assert.match(id, hashPattern);
  26. });
  27. });
  28. describe('Sync call: machineIdSync()', function() {
  29. it('should return unique sha256-hash', () => {
  30. assert.match(machineIdSync(), hashPattern);
  31. });
  32. });
  33. describe('CommonJS imports', function () {
  34. it('should return function machineIdSync, machineId', function () {
  35. let __module__ = require('../dist/index');
  36. assert.isFunction(__module__.machineId);
  37. assert.isFunction(__module__.machineIdSync);
  38. });
  39. });