Skip to content

Commit

Permalink
Setup for Circle 2 (jestjs#4149)
Browse files Browse the repository at this point in the history
* Setup for Circle 2

* Try to reuse config

* Fix aliases and add browser build

* Adjust config

* Fix save-cache alias

* Add website/node_modules to alias cache

* Change browser docker

* Add working_directory

* add yarn-install-no-sudo

* Remove environment

* Actually skip react-native example on Node 4

* Declare transitive deps in corresponding package.json

* Install node 4 deps with yarn

* Setup import/no-extraneous-dependencies rule
  • Loading branch information
thymikee authored and cpojer committed Aug 8, 2017
1 parent 192a99f commit b3c4338
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 64 deletions.
111 changes: 111 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
aliases:
- &restore-cache
keys:
- dependencies-{{ .Branch }}-{{ checksum "package.json" }}
# Fallback in case checksum fails
- dependencies-{{ .Branch }}-

- &save-cache
paths:
- node_modules
- website/node_modules
key: dependencies-{{ .Branch }}-{{ checksum "package.json" }}

- &yarn-install
run: |
sudo npm i -g yarn@^0.27.5
yarn --no-progress
- &yarn-install-no-sudo
run: |
npm i -g yarn@^0.27.5
yarn --no-progress
- &deploy
command: |
# Deploy Jest website
git config --global user.email "[email protected]"
git config --global user.name "Website Deployment Script"
echo "machine github.com login jest-bot password $GITHUB_TOKEN" > ~/.netrc
# crowdin install start
sudo apt-get install default-jre
wget https://artifacts.crowdin.com/repo/deb/crowdin.deb -O crowdin.deb
sudo dpkg -i crowdin.deb
# crowdin install end
crowdin --config crowdin.yaml upload sources --auto-update -b master
crowdin --config crowdin.yaml download -b master
cd website && GIT_USER=jest-bot npm run gh-pages
version: 2
jobs:
test-browser:
working_directory: ~/jest
docker:
- image: markhobson/node-chrome
steps:
- checkout
- restore-cache: *restore-cache
- *yarn-install-no-sudo
- save-cache: *save-cache
- run: yarn run test-ci-es5-build-in-browser

test-node-8:
working_directory: ~/jest
docker:
- image: circleci/node:8.1.4
steps:
- checkout
- restore-cache: *restore-cache
- *yarn-install
- save-cache: *save-cache
- run: yarn run test-ci-partial

test-node-6:
working_directory: ~/jest
docker:
- image: circleci/node:6.11.0
steps:
- checkout
- restore-cache: *restore-cache
- *yarn-install
- save-cache: *save-cache
- run: yarn run test-ci

test-node-4:
working_directory: ~/jest
docker:
- image: circleci/node:4.8.4
steps:
- checkout
- restore-cache: *restore-cache
- *yarn-install
- save-cache: *save-cache
- run: npm run test-ci-partial

test-and-deploy-website:
working_directory: ~/jest
docker:
- image: circleci/node:8.1.4
steps:
- checkout
- restore-cache: *restore-cache
- run: sudo npm i -g yarn@^0.27.5
- run: |
cd website
yarn --no-progress
- save-cache: *save-cache
- run: |
cd website
yarn run test
- deploy: *deploy

# Workflows enables us to run multiple jobs in parallel
workflows:
version: 2
build-and-deploy:
jobs:
- test-node-8
- test-node-6
- test-node-4
- test-browser
- test-and-deploy-website
38 changes: 38 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

const path = require('path');
const customImportResolver = path.resolve('./eslint_import_resolver');

module.exports = {
extends: [
'./packages/eslint-config-fb-strict/index.js',
Expand All @@ -19,6 +22,7 @@ module.exports = {
files: ['*.md'],
rules: {
'consistent-return': 0,
'import/no-extraneous-dependencies': 0,
'import/no-unresolved': 0,
'jest/no-focused-tests': 0,
'jest/no-identical-title': 0,
Expand Down Expand Up @@ -76,6 +80,7 @@ module.exports = {
'scripts/**/*',
'integration_tests/*/**/*',
'website/*/**/*',
'eslint_import_resolver.js',
],
rules: {
'prettier/prettier': [
Expand Down Expand Up @@ -109,6 +114,17 @@ module.exports = {
'flowtype/require-valid-file-annotation': [2, 'always'],
},
},
{
files: [
'website/**',
'**/__tests__/**',
'integration_tests/**',
'**/pretty-format/perf/**',
],
rules: {
'import/no-extraneous-dependencies': 0,
},
},
],
parser: 'babel-eslint',
plugins: ['markdown', 'import', 'unicorn', 'prettier'],
Expand All @@ -120,6 +136,19 @@ module.exports = {
'import/default': 0,
'import/named': 0,
'import/no-duplicates': 2,
'import/no-extraneous-dependencies': [
2,
{
devDependencies: [
'**/__tests__/**',
'**/__mocks__/**',
'**/?(*.)(spec|test).js?(x)',
'scripts/**',
'eslint_import_resolver.js',
'test_setup_file.js',
],
},
],
'import/no-unresolved': [2, {ignore: ['^types/']}],
// This has to be disabled until all type and module imports are combined
// https://github.com/benmosher/eslint-plugin-import/issues/645
Expand All @@ -136,4 +165,13 @@ module.exports = {
],
'unicorn/filename-case': [2, {case: 'snakeCase'}],
},
settings: {
'import/resolver': {
[customImportResolver]: {
moduleNameMapper: {
'^types/(.*)': './types/$1',
},
},
},
},
};
50 changes: 0 additions & 50 deletions circle.yml

This file was deleted.

83 changes: 83 additions & 0 deletions eslint_import_resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Copyright (c) 2014, 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.
*
* Adapted from node resolver: https://github.com/benmosher/eslint-plugin-import/tree/master/resolvers/node
*
*/

'use strict';

const resolve = require('resolve');
const path = require('path');

const log = require('debug')('eslint-plugin-import:resolver:node');

module.exports.interfaceVersion = 2;

module.exports.resolve = function(source, file, config) {
log('Resolving:', source, 'from:', file);
let resolvedPath;

if (resolve.isCore(source)) {
log('resolved to core');
return {found: true, path: null};
}

source = applyModuleNameMapper(source, config);

try {
resolvedPath = resolve.sync(source, opts(file, config));
log('Resolved to:', resolvedPath);
return {found: true, path: resolvedPath};
} catch (err) {
log('resolve threw error:', err);
return {found: false};
}
};

function opts(file, config) {
return Object.assign(
{
// more closely matches Node (#333)
extensions: ['.js', '.json'],
},
config,
{
// path.resolve will handle paths relative to CWD
basedir: path.dirname(path.resolve(file)),
packageFilter,
}
);
}

function packageFilter(pkg) {
if (pkg['jsnext:main']) {
pkg['main'] = pkg['jsnext:main'];
}
return pkg;
}

function applyModuleNameMapper(source, config) {
Object.keys(config.moduleNameMapper).forEach(regex => {
const mappedModuleName = config.moduleNameMapper[regex];

if (source.match(regex)) {
const matches = source.match(regex);
if (!matches) {
source = mappedModuleName;
} else {
source = mappedModuleName.replace(
/\$([0-9]+)/g,
(_, index) => matches[parseInt(index, 10)]
);
}
source = path.resolve(source);
}
});

return source;
}
6 changes: 3 additions & 3 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"dependencies": {
"react": "15.4.2",
"react-dom": "15.4.2"
"react-dom": "15.4.2",
"typescript": "*"
},
"devDependencies": {
"@types/jest": "^19.2.4",
"jest": "*",
"react-addons-test-utils": "15.4.2",
"typescript": "*"
"react-addons-test-utils": "15.4.2"
},
"scripts": {
"test": "jest"
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"chalk": "^2.0.1",
"codecov": "^1.0.1",
"cross-spawn": "^5.1.0",
"debug": "^2.6.8",
"enzyme": "^2.8.2",
"eslint": "^4.2.0",
"eslint-config-prettier": "^2.3.0",
Expand Down Expand Up @@ -59,6 +60,7 @@
"react-dom": "^15.6.1",
"react-test-renderer": "15.4.2",
"regenerator-runtime": "^0.10.3",
"resolve": "^1.4.0",
"rimraf": "^2.5.4",
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.7.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-circus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"license": "BSD-3-Clause",
"main": "build/index.js",
"dependencies": {
"chalk": "^2.0.1",
"jest-snapshot": "^20.0.3",
"jest-matchers": "^20.0.3",
"jest-matcher-utils": "^20.0.3",
"jest-message-util": "^20.0.3",
"jest-diff": "^20.0.3"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import type {Environment} from 'types/Environment';
import type {GlobalConfig, ProjectConfig} from 'types/Config';
import type {TestResult} from 'types/TestResult';
// eslint-disable-next-line import/no-extraneous-dependencies
import type Runtime from 'jest-runtime';

const FRAMEWORK_INITIALIZER = require.resolve('./jest-adapter-init');
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"jest-matcher-utils": "^20.0.3",
"jest-regex-util": "^20.0.3",
"jest-resolve": "^20.0.4",
"jest-util": "^20.0.3",
"jest-validate": "^20.0.3",
"pretty-format": "^20.0.3"
}
Expand Down
1 change: 1 addition & 0 deletions packages/jest-jasmine2/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {Environment} from 'types/Environment';
import type {GlobalConfig, ProjectConfig} from 'types/Config';
import type {SnapshotState} from 'jest-snapshot';
import type {TestResult} from 'types/TestResult';
// eslint-disable-next-line import/no-extraneous-dependencies
import type Runtime from 'jest-runtime';

import path from 'path';
Expand Down
Loading

0 comments on commit b3c4338

Please sign in to comment.