Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new jest globals #1632

Merged
merged 1 commit into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions integration_tests/__tests__/__snapshots__/globals-test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
exports[`test global jest variables 1`] = `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THIS IS SOOOOO COOOOL!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually an awesome use of snapshot testing!

" PASS __tests__/globals-test.js
✓ it.only
✓ test.only
○ it
○ test
○ it.skip
○ test.skip
○ xit
○ xtest
fdescribe
✓ test
describe.only
✓ test
describe
○ test

Test Summary
› Ran all tests."
`;
30 changes: 21 additions & 9 deletions integration_tests/__tests__/globals-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@
* 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.
*
* @emails oncall+jsinfra
*/

'use strict';

describe('Common globals', () => {
it('check process', () => {
if (Symbol && Symbol.toStringTag) {
expect(Object.prototype.toString.call(global.process))
.toBe('[object process]');
}
});
const path = require('path');
const runJest = require('../runJest');
const skipOnWindows = require('skipOnWindows');

skipOnWindows.suite();

const dir = path.resolve(__dirname, '../globals');

test('global jest variables', () => {
const {stderr, status} = runJest(dir);

expect(status).toBe(0);

const output = stderr
.split('\n')
.slice(0, -2)
.join('\n')
.replace(/\s*\(.*ms\)/gm, '');

expect(output).toMatchSnapshot();
});
40 changes: 40 additions & 0 deletions integration_tests/globals/__tests__/globals-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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';

it('it', () => {});
test('test', () => {});

describe('describe', () => {
test('test', () => {});
});

fdescribe('fdescribe', () => {
test('test', () => {});
});

describe.only('describe.only', () => {
test('test', () => {});
});

it.skip('it.skip', () => {});
test.skip('test.skip', () => {});

it.only('it.only', () => {});
test.only('test.only', () => {});

xit('xit', () => {});
/* eslint-disable no-undef */
xtest('xtest', () => {});
/* eslint-enable no-undef */

xdescribe('xdescribe', () => {
test('test');
});
1 change: 1 addition & 0 deletions integration_tests/globals/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
19 changes: 19 additions & 0 deletions packages/jest-cli/src/__tests__/globals-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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.
*
* @emails oncall+jsinfra
*/
'use strict';

describe('Common globals', () => {
it('check process', () => {
if (Symbol && Symbol.toStringTag) {
expect(Object.prototype.toString.call(global.process))
.toBe('[object process]');
}
});
});
12 changes: 12 additions & 0 deletions packages/jest-jasmine2/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,19 @@ function jasmine2(
env.addReporter(jasmineInterface.jsApiReporter);

jasmineAsync.install(environment.global);

environment.global.test = environment.global.it;
environment.global.it.only = environment.global.fit;
environment.global.test.only = environment.global.fit;
environment.global.it.skip = environment.global.xit;
environment.global.test.skip = environment.global.xit;
environment.global.xtest = environment.global.xit;
environment.global.context = environment.global.describe;
environment.global.xcontext = environment.global.xdescribe;
environment.global.context.skip = environment.global.xdescribe;
environment.global.describe.skip = environment.global.xdescribe;
environment.global.describe.only = environment.global.fdescribe;


if (config.setupTestFrameworkScriptFile) {
runtime.requireModule(config.setupTestFrameworkScriptFile);
Expand Down