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.
This commit is contained in:
Steve Gravrock
2020-01-11 10:49:37 -08:00
parent 17e9088ac5
commit fffb8abb24
5 changed files with 91 additions and 72 deletions

View File

@@ -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; }

View File

@@ -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());

View File

@@ -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()
}
);
});
});
});

View File

@@ -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,

View File

@@ -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