From fffb8abb244ee95551b42ace75ff6f21428ce157 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 11 Jan 2020 10:49:37 -0800 Subject: [PATCH] Moved property tests to the main suite Property tests can only run in Node, so they were previously in another directory that only gets run in Node. Now they're next to the related non-property tests and marked pending in the browser. This makes it more likely that a developer who normally only runs tests in the browser will notice and run them. --- spec/core/matchers/matchersUtilSpec.js | 73 +++++++++++++++++++++++++- spec/helpers/requireFastCheck.js | 16 ++++++ spec/property/matchersUtilSpec.js | 69 ------------------------ spec/support/jasmine-browser.js | 3 +- spec/support/jasmine.json | 2 +- 5 files changed, 91 insertions(+), 72 deletions(-) create mode 100644 spec/helpers/requireFastCheck.js delete mode 100644 spec/property/matchersUtilSpec.js diff --git a/spec/core/matchers/matchersUtilSpec.js b/spec/core/matchers/matchersUtilSpec.js index b2146e94..508a5bfd 100644 --- a/spec/core/matchers/matchersUtilSpec.js +++ b/spec/core/matchers/matchersUtilSpec.js @@ -1,5 +1,76 @@ describe("matchersUtil", function() { describe("equals", function() { + describe('Properties', function() { + var fc; + + beforeEach(function() { + fc = jasmine.getEnv().requireFastCheck(); + }); + + function basicAnythingSettings() { + return { + key: fc.oneof(fc.string(), fc.constantFrom('k1', 'k2', 'k3')), + // Limiting depth & number of keys allows fast-check to try + // a lot more scalar values. + maxDepth: 2, + maxKeys: 5, + withBoxedValues: true, + withMap: true, + withSet: true + }; + } + + function numRuns() { + var many = 5000000; + + // Be thorough but very slow when specified (usually on CI). + if (process.env.JASMINE_LONG_PROPERTY_TESTS) { + console.log( + 'Using', + many, + 'runs of fc.assert because JASMINE_LONG_PROPERTY_TESTS was set. This may take several minutes.' + ); + return many; + } else { + return undefined; + } + } + + it('is symmetric', function() { + fc.assert( + fc.property( + fc.anything(basicAnythingSettings()), + fc.anything(basicAnythingSettings()), + function(a, b) { + return ( + jasmineUnderTest.matchersUtil.equals(a, b) === + jasmineUnderTest.matchersUtil.equals(b, a) + ); + } + ), + { + numRuns: numRuns(), + examples: [[0, 5e-324]] + } + ); + }); + + it('is reflexive', function() { + var anythingSettings = basicAnythingSettings(); + anythingSettings.withMap = false; + fc.assert( + fc.property(fc.dedup(fc.anything(anythingSettings), 2), function( + values + ) { + return jasmineUnderTest.matchersUtil.equals(values[0], values[1]); + }), + { + numRuns: numRuns() + } + ); + }); + }); + it("passes for literals that are triple-equal", function() { expect(jasmineUnderTest.matchersUtil.equals(null, null)).toBe(true); expect(jasmineUnderTest.matchersUtil.equals(void 0, void 0)).toBe(true); @@ -164,7 +235,7 @@ describe("matchersUtil", function() { expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true); }); - + it("passes for equivalent Promises (GitHub issue #1314)", function() { if (typeof Promise === 'undefined') { return; } diff --git a/spec/helpers/requireFastCheck.js b/spec/helpers/requireFastCheck.js new file mode 100644 index 00000000..140b8e80 --- /dev/null +++ b/spec/helpers/requireFastCheck.js @@ -0,0 +1,16 @@ +(function(env) { + var NODE_JS = + typeof process !== 'undefined' && + process.versions && + typeof process.versions.node === 'string'; + + env.requireFastCheck = function() { + if (!NODE_JS) { + env.pending( + "Property tests don't run in the browser. Use `npm test` to run them." + ); + } + + return require('fast-check'); + }; +})(jasmine.getEnv()); diff --git a/spec/property/matchersUtilSpec.js b/spec/property/matchersUtilSpec.js deleted file mode 100644 index 384a1f14..00000000 --- a/spec/property/matchersUtilSpec.js +++ /dev/null @@ -1,69 +0,0 @@ -describe('matchersUtil -- property tests', function() { - 'use strict'; - var fc = require('fast-check'); - - function basicAnythingSettings() { - return { - key: fc.oneof(fc.string(), fc.constantFrom('k1', 'k2', 'k3')), - // Limiting depth & number of keys allows fast-check to try - // a lot more scalar values. - maxDepth: 2, - maxKeys: 5, - withBoxedValues: true, - withMap: true, - withSet: true - }; - } - - function numRuns() { - var many = 5000000; - - // Be thorough but very slow when specified (usually on CI). - if (process.env.JASMINE_LONG_PROPERTY_TESTS) { - console.log( - 'Using', - many, - 'runs of fc.assert because JASMINE_LONG_PROPERTY_TESTS was set. This may take several minutes.' - ); - return many; - } else { - return undefined; - } - } - - describe('equals', function() { - it('is symmetric', function() { - fc.assert( - fc.property( - fc.anything(basicAnythingSettings()), - fc.anything(basicAnythingSettings()), - function(a, b) { - return ( - jasmineUnderTest.matchersUtil.equals(a, b) === - jasmineUnderTest.matchersUtil.equals(b, a) - ); - } - ), - { - numRuns: numRuns(), - examples: [[0, 5e-324]] - } - ); - }); - - it('is reflexive', function() { - var anythingSettings = basicAnythingSettings(); - anythingSettings.withMap = false; - fc.assert( - fc.property(fc.dedup(fc.anything(anythingSettings), 2), function( - values - ) { - return jasmineUnderTest.matchersUtil.equals(values[0], values[1]); - }), - { - numRuns: numRuns() - } - ); - }); - }); -}); diff --git a/spec/support/jasmine-browser.js b/spec/support/jasmine-browser.js index bbc9c4ac..61076dbb 100644 --- a/spec/support/jasmine-browser.js +++ b/spec/support/jasmine-browser.js @@ -15,7 +15,7 @@ module.exports = { '**/*.js' ], specDir: 'spec', - specFiles: ['**/*[Ss]pec.js', '!npmPackage/**/*', '!property/**/*'], + specFiles: ['**/*[Ss]pec.js', '!npmPackage/**/*'], helpers: [ 'helpers/asyncAwait.js', 'helpers/BrowserFlags.js', @@ -26,6 +26,7 @@ module.exports = { 'helpers/domHelpers.js', 'helpers/integrationMatchers.js', 'helpers/promises.js', + 'helpers/requireFastCheck.js', 'helpers/defineJasmineUnderTest.js' ], random: true, diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json index 6ce73409..b48efde5 100644 --- a/spec/support/jasmine.json +++ b/spec/support/jasmine.json @@ -2,7 +2,6 @@ "spec_dir": "spec", "spec_files": [ "core/**/*[Ss]pec.js", - "property/**/*[Ss]pec.js", "npmPackage/**/*[Ss]pec.js" ], "helpers": [ @@ -14,6 +13,7 @@ "helpers/domHelpers.js", "helpers/integrationMatchers.js", "helpers/promises.js", + "helpers/requireFastCheck.js", "helpers/nodeDefineJasmineUnderTest.js" ], "random": true