forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Adds support for property testing via Lee Byron's testcheck-js library. <s>This cannot merge until this merges: https://github.com/leebyron/jasmine-check/pull/5</s> Please see the documentation for testcheck: https://github.com/leebyron/testcheck-js (bypass-lint) Closes jestjs#1083 Differential Revision: D3369819 fbshipit-source-id: d8eb3f24711346d47bd7bde06c7d3a1a1f70c2e3
- Loading branch information
1 parent
cdd49d1
commit 5bdcf79
Showing
16 changed files
with
295 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
## master | ||
|
||
* Add support for property testing via testcheck-js. | ||
|
||
## jest-cli 12.1.1 | ||
|
||
* Windows stability fixes. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
jest.unmock('../runJest'); | ||
|
||
const runJest = require('../runJest'); | ||
|
||
describe('testcheck', () => { | ||
it('works', () => { | ||
const result = runJest.json('testcheck', ['testcheck-test.js']); | ||
const json = result.json; | ||
|
||
expect(json.numTotalTests).toBe(3); | ||
expect(json.numPassedTests).toBe(1); | ||
expect(json.numFailedTests).toBe(1); | ||
expect(json.numPendingTests).toBe(1); | ||
}); | ||
|
||
it('runs "fit" tests exclusively', () => { | ||
const result = runJest.json('testcheck', ['testcheck-fit-test.js']); | ||
const json = result.json; | ||
|
||
expect(json.numTotalTests).toBe(3); | ||
expect(json.numPassedTests).toBe(1); | ||
expect(json.numFailedTests).toBe(0); | ||
expect(json.numPendingTests).toBe(2); | ||
}); | ||
|
||
it('merges in testcheck options', () => { | ||
const result = runJest.json('testcheck', [ | ||
'testcheck-options-test.js', | ||
'--testcheckSeed', '0', | ||
'--testcheckTimes', '5', | ||
'--testcheckMaxSize', '2', | ||
]); | ||
const json = result.json; | ||
const output = result.stderr.toString(); | ||
|
||
expect(json.numTotalTests).toBe(4); | ||
expect(json.numPassedTests).toBe(4); | ||
|
||
expect(output).toMatch(/An array: \[ 1, 9, -5, 4, 3, 8 \]/); | ||
expect(output).toMatch(/runCountWithoutOverride: 5/); | ||
expect(output).toMatch(/runCountWithOverride: 1/); | ||
}); | ||
|
||
it('reports exceptions', () => { | ||
const result = runJest('testcheck', ['testcheck-exceptions-test.js']); | ||
expect(result.status).toBe(1); | ||
expect(result.stdout.toString()).toMatch( | ||
/Error: This error should be reported/ | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
integration_tests/testcheck/__tests__/testcheck-exceptions-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('testcheck-exceptions', () => { | ||
check.it('reports exceptions', [], () => { | ||
throw new Error('This error should be reported.'); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
integration_tests/testcheck/__tests__/testcheck-fit-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('testcheck-fit', () => { | ||
check.fit('runs tests with fit exclusively', [], () => { | ||
expect(true).toBe(true); | ||
}); | ||
|
||
check.it('should not run this test', [], () => { | ||
expect(true).toBe(false); | ||
}); | ||
|
||
it('should not run this test either', () => { | ||
expect(true).toBe(false); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
integration_tests/testcheck/__tests__/testcheck-options-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
let runCountWithoutOverride = 0; | ||
let runCountWithOverride = 0; | ||
|
||
describe('testcheck-options', () => { | ||
check.it('runs things ten times by default', [], () => { | ||
runCountWithoutOverride++; | ||
}); | ||
|
||
check.it('allows overrides', {times: 1}, [], () => { | ||
runCountWithOverride++; | ||
}); | ||
|
||
check.it('generates correctly-sized arrays', [gen.array(gen.int)], a => { | ||
expect(a.length).toBeLessThan(2); | ||
}); | ||
|
||
check.it('has the right seed', [gen.resize(10, gen.array(gen.int))], a => { | ||
console.log('An array:', a); | ||
}); | ||
|
||
afterAll(() => { | ||
console.log('runCountWithoutOverride:', runCountWithoutOverride); | ||
console.log('runCountWithOverride:', runCountWithOverride); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('testcheck', () => { | ||
check.it('works', [gen.int], a => { | ||
expect(a).toEqual(jasmine.any(Number)); | ||
}); | ||
|
||
check.it('reports failures', [], () => { | ||
expect(true).toBe(false); | ||
}); | ||
|
||
check.xit('skips tests', [], () => { | ||
expect(true).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
jest.unmock('jasmine-check'); | ||
require('jasmine-check').install(); | ||
|
||
// Replace the 'check' functions with ones that default to options from | ||
// the jest configuration: | ||
(() => { | ||
const configOptions = global.jasmine.testcheckOptions; | ||
const check = global.check; | ||
const makeMergeOptions = (object, methodName) => { | ||
const original = object[methodName]; | ||
object[methodName] = (specName, options, gens, propertyFn) => { | ||
if (!propertyFn) { | ||
propertyFn = gens; | ||
gens = options; | ||
options = {}; | ||
} | ||
const mergedOptions = Object.assign({}, configOptions, options); | ||
return original(specName, mergedOptions, gens, propertyFn); | ||
}; | ||
}; | ||
|
||
makeMergeOptions(check, 'it'); | ||
makeMergeOptions(check, 'iit'); | ||
makeMergeOptions(check.it, 'only'); | ||
makeMergeOptions(check, 'fit'); | ||
makeMergeOptions(check, 'xit'); | ||
})(); |