Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.
Open
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
49 changes: 33 additions & 16 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ module.exports = {
node: true,
},

extends: [

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ugh.. seems like this file wasn't prettified before

'plugin:jsx-a11y/recommended',
],
extends: ['plugin:jsx-a11y/recommended'],

globals: {
atom: false,
Expand Down Expand Up @@ -90,13 +88,13 @@ module.exports = {
'array-callback-return': 0,
'block-scoped-var': 0,
'class-methods-use-this': 0,
'complexity': 0,
complexity: 0,
'consistent-return': 0,
'curly': 1,
curly: 1,
'default-case': 0,
'dot-location': [1, 'property'],
'dot-notation': 1,
'eqeqeq': [1, 'always', {null: 'never'}],
eqeqeq: [1, 'always', {null: 'never'}],
'getter-return': 2,
'guard-for-in': 0,
'no-alert': 0,
Expand Down Expand Up @@ -152,15 +150,15 @@ module.exports = {
'no-warning-comments': 0,
'no-with': 1,
'prefer-promise-reject-errors': 1,
'radix': 1,
radix: 1,
'require-await': 0,
// 'require-await': 1,
'vars-on-top': 0,
'wrap-iife': [1, 'inside'],
'yoda': 1,
yoda: 1,

// Strict Mode (http://eslint.org/docs/rules/#strict-mode)
'strict': 0,
strict: 0,

// Variables (http://eslint.org/docs/rules/#variables)
'init-declarations': 0,
Expand Down Expand Up @@ -192,7 +190,7 @@ module.exports = {
'array-bracket-spacing': 1,
'block-spacing': 1,
'brace-style': [1, '1tbs', {allowSingleLine: true}],
'camelcase': 0,
camelcase: 0,
'capitalized-comments': 0,
'comma-dangle': 0,
'comma-spacing': 1,
Expand Down Expand Up @@ -256,20 +254,30 @@ module.exports = {
'one-var': [1, 'never'],
'operator-assignment': 1,
'operator-linebreak': 0,
'padded-blocks': [1, {blocks: 'never', classes: 'never', switches: 'never'}],
'padded-blocks': [
1,
{blocks: 'never', classes: 'never', switches: 'never'},
],
// 'quote-props': [1, 'as-needed'],
'quotes': [1, 'single', 'avoid-escape'],
quotes: [1, 'single', 'avoid-escape'],
'require-jsdoc': 0,
// 'semi-spacing': 1,
'semi': 1,
semi: 1,
'sort-keys': 0,
'sort-vars': 0,
'space-before-blocks': 1,
'space-before-function-paren': [1, {anonymous: 'never', named: 'never', asyncArrow: 'always'}],
'space-before-function-paren': [
1,
{anonymous: 'never', named: 'never', asyncArrow: 'always'},
],
'space-in-parens': [1, 'never'],
'space-infix-ops': 1,
'space-unary-ops': 1,
'spaced-comment': [1, 'always', {line: {exceptions: ['-']}, block: {balanced: true}}],
'spaced-comment': [
1,
'always',
{line: {exceptions: ['-']}, block: {balanced: true}},
],
'template-tag-spacing': 1,
'unicode-bom': [1, 'never'],
'wrap-regex': 0,
Expand Down Expand Up @@ -414,7 +422,10 @@ module.exports = {
'react/sort-prop-types': 0,
'react/style-prop-object': 0,
'react/jsx-boolean-value': 0,
'react/jsx-closing-bracket-location': [1, {selfClosing: 'tag-aligned', nonEmpty: 'after-props'}],
'react/jsx-closing-bracket-location': [
1,
{selfClosing: 'tag-aligned', nonEmpty: 'after-props'},
],
// 'react/jsx-curly-spacing': [1, 'never'],
'react/jsx-equals-spacing': 0,
'react/jsx-filename-extension': 0,
Expand Down Expand Up @@ -551,6 +562,12 @@ module.exports = {
'unicorn/no-unsafe-regex': 0,
'unicorn/prefer-add-event-listener': 0,
},
overrides: [
{
files: ['jest/**/*.js'],
rules: {'nuclide-internal/license-header': [1, {useBSDLicense: false}]},
},
],

plugins: [
'dependencies',
Expand Down
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;
Loading