Skip to content

Commit

Permalink
Allow semver to be unrequireable
Browse files Browse the repository at this point in the history
  • Loading branch information
scagood committed Sep 10, 2023
1 parent 2abe2d5 commit 437a656
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
14 changes: 14 additions & 0 deletions test/lib/semver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

var semver;
try {
// eslint-disable-next-line global-require
semver = require('semver');
} catch (error) {
}

function shouldSkipVersion(version) {
return !semver || semver.satisfies(process.version, version);
}

module.exports = shouldSkipVersion;
4 changes: 2 additions & 2 deletions test/mutability.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var test = require('tape');
var semver = require('semver');
var shouldSkipVersion = require('./lib/semver');
var assert = require('assert');
var traverse = require('../');
var deepEqual = require('./lib/deep_equal');
Expand Down Expand Up @@ -79,7 +79,7 @@ test('cloneT', function (t) {
});

/* global Uint8Array */
test('cloneTypedArray', { skip: semver.satisfies(process.version, '< 4') }, function (t) {
test('cloneTypedArray', { skip: shouldSkipVersion('< 4') }, function (t) {
var obj = Uint8Array.from([1]);
var res = traverse.clone(obj);

Expand Down
4 changes: 2 additions & 2 deletions test/typed-array.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

var test = require('tape');
var semver = require('semver');
var shouldSkipVersion = require('./lib/semver');
var traverse = require('../');

/* global Uint8Array */
test('traverse an UInt8Array', { skip: semver.satisfies(process.version, '< 4') }, function (t) {
test('traverse an UInt8Array', { skip: shouldSkipVersion('< 4') }, function (t) {
var obj = Uint8Array.from('test');
var results = traverse(obj).map(function () {});
t.same(results, obj);
Expand Down

0 comments on commit 437a656

Please sign in to comment.