Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
sync jest dir
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov committed Jun 21, 2018
1 parent 185194b commit 0c6f35f
Show file tree
Hide file tree
Showing 16 changed files with 334 additions and 0 deletions.
18 changes: 18 additions & 0 deletions jest/__atom_tests__/builtin-modules-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @flow strict-local
* @format
*/

test('pass', () => {
const atom = require('atom');
const electron = require('electron');

expect(atom).toBeDefined();
expect(electron).toBeDefined();
});
16 changes: 16 additions & 0 deletions jest/__atom_tests__/fake_timers-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @flow strict-local
* @format
*/

test('fake timers are not available yet', () => {
expect(() => {
jest.useFakeTimers();
}).toThrow('fakeTimers are not supproted in atom environment');
});
14 changes: 14 additions & 0 deletions jest/__atom_tests__/sample-1-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @flow strict
* @format
*/

test('atom', () => {
expect(1).toBe(1);
});
14 changes: 14 additions & 0 deletions jest/__atom_tests__/sample-2-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @flow strict
* @format
*/

test('atom', () => {
expect(2).toBe(2);
});
13 changes: 13 additions & 0 deletions jest/__mocks__/emptyObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @flow strict
* @format
*/

// eslint-disable-next-line nuclide-internal/no-commonjs
module.exports = {};
36 changes: 36 additions & 0 deletions jest/__mocks__/log4js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @flow strict
* @format
*/

const logger: log4js$Logger = {
debug: jest.fn(),
error: jest.fn(),
fatal: jest.fn(),
info: jest.fn(),
isLevelEnabled: jest.fn(),
// $FlowFixMe
level: jest.fn(),
log: jest.fn(),
mark: jest.fn(),
removeLevel: jest.fn(),
setLevel: jest.fn(),
trace: jest.fn(),
warn: jest.fn(),
};

export const getLogger = (name: string): log4js$Logger => logger;

const log4js = {
getLogger,
// $FlowFixMe
configure: jest.fn(),
};

export default log4js;
35 changes: 35 additions & 0 deletions jest/__mocks__/nuclide-commons/analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @flow
* @format
*/

export function trackTiming<T>(
eventName: string,
operation: () => T,
values?: {[key: string]: any} = {},
): T {
return operation();
}

export const track: any = jest.fn();

export const startTracking = () => {
const timingTracker: any = {
onError: jest.fn(),
onSuccess: jest.fn(),
};

return timingTracker;
};

export const trackImmediate: any = jest.fn();

export const setRawAnalyticsService: any = jest.fn();

export const trackTimingSampled: any = jest.fn((event, fn) => fn());
28 changes: 28 additions & 0 deletions jest/__tests__/waits_for-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @flow strict
* @format
*/

import waitsFor from '../waits_for';

it('waits', async () => {
let condition = false;
Promise.resolve().then(() => (condition = true));
await waitsFor(() => condition);
});

it("can't wait anymore", async () => {
await expect(waitsFor(() => false, undefined, 1)).rejects.toThrow(
'but it never did',
);
});

it('gives a message', async () => {
await expect(waitsFor(() => false, 'lol', 1)).rejects.toThrow('lol');
});
15 changes: 15 additions & 0 deletions jest/build_atom_jest_runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the LICENSE file in
# the root directory of this source tree.

THIS_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
FBSOURCE_ROOT=$(realpath "$THIS_DIR""/../../..")


cd "$FBSOURCE_ROOT""/xplat/nuclide/modules/jest-atom-runner" || exit

./node_modules/.bin/babel src --out-dir build
36 changes: 36 additions & 0 deletions jest/jest.config.atom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @noflow
*/
'use strict';

/* eslint
comma-dangle: [1, always-multiline],
prefer-object-spread/prefer-object-spread: 0,
nuclide-internal/no-commonjs: 0,
*/

const path = require('path');

module.exports = {
displayName: 'atom',
rootDir: path.resolve(__dirname, '../../..'),
roots: ['<rootDir>/xplat/nuclide'],
testMatch: ['**/__atom_tests__/**/*.js?(x)'],
transform: {
'\\.js$': '<rootDir>/xplat/nuclide/modules/nuclide-jest/jestTransformer.js',
},
setupTestFrameworkScriptFile: '<rootDir>/xplat/nuclide/jest/setupTestFrameworkScriptFile.atom.js',
testPathIgnorePatterns: ['/node_modules/'],
runner: path.resolve(__dirname, '../modules/jest-atom-runner/build/index.js'),
moduleNameMapper: {
oniguruma: path.resolve(__dirname, './__mocks__/emptyObject.js'),
},
testEnvironment:
'<rootDir>/xplat/nuclide/modules/jest-atom-runner/build/environment.js',
};
31 changes: 31 additions & 0 deletions jest/jest.config.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @noflow
*/
'use strict';

/* eslint
comma-dangle: [1, always-multiline],
prefer-object-spread/prefer-object-spread: 0,
nuclide-internal/no-commonjs: 0,
*/

const path = require('path');

module.exports = {
displayName: 'node',
rootDir: path.resolve(__dirname, '../../../'),
roots: ['<rootDir>/xplat/nuclide'],
testMatch: ['**/__tests__/**/*.js?(x)'],
transform: {
'\\.js$': '<rootDir>/xplat/nuclide/modules/nuclide-jest/jestTransformer.js',
},
setupTestFrameworkScriptFile: '<rootDir>/xplat/nuclide/jest/setupTestFrameworkScriptFile.node.js',
setupFiles: ['<rootDir>/xplat/nuclide/jest/setup.js'],
testPathIgnorePatterns: ['/node_modules/'],
};
15 changes: 15 additions & 0 deletions jest/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @flow strict
* @format
*/

jest.mock('nuclide-commons/analytics');
jest.mock('log4js');

global.NUCLIDE_DO_NOT_LOG = true;
17 changes: 17 additions & 0 deletions jest/setupTestFrameworkScriptFile.atom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @flow strict-local
* @format
*/

beforeEach(async () => {
await global.atom.reset();
});

// Disable prompt to download react devtools in atom tests
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {isDisabled: true};
12 changes: 12 additions & 0 deletions jest/setupTestFrameworkScriptFile.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @flow strict-local
* @format
*/

jest.setTimeout(10000);
33 changes: 33 additions & 0 deletions jest/waits_for.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*
* @flow strict
* @format
*/

/*
* Async implementation of Jasmine's waitsFor()
*/
export default (async function waitsFor(
fn: () => boolean,
message?: string,
timeout: number = 4500,
) {
const error = new Error(
message != null
? message
: 'Expected the function to start returning "true" but it never did',
);
const startTime = Date.now();
while (!Boolean(fn())) {
if (Date.now() - startTime > timeout) {
throw error;
}
// eslint-disable-next-line no-await-in-loop
await new Promise(resolve => setTimeout(resolve, 50));
}
});
1 change: 1 addition & 0 deletions scripts/sync-nuclide.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SYNC_PATHS=(
'flow-libs'
'flow-typed'
'modules'
'jest'
':!modules/big-dig*'
':!modules/nuclide-debugger-cli'
':!modules/nuclide-debugger-vsps'
Expand Down

0 comments on commit 0c6f35f

Please sign in to comment.