Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,4 @@
**/__mocks__/**
**/__tests__/**
src
yarn.lock

View File

@@ -0,0 +1,25 @@
# babel-jest
[Babel](https://github.com/babel/babel) [jest](https://github.com/facebook/jest) plugin
## Usage
If you are already using `jest-cli`, just add `babel-jest` and it will automatically compile JavaScript code using babel.
```
npm install --save-dev babel-jest
```
If you would like to write your own preprocessor, uninstall and delete babel-jest and set the [config.transform](http://facebook.github.io/jest/docs/configuration.html#transform-object-string-string) option to your preprocessor.
## Setup
*Note: this step is only required if you are using `babel-jest` with additional code preprocessors.*
To explicitly define `babel-jest` as a transformer for your JavaScript code, map *.js* files to the `babel-jest` module.
```json
"transform": {
"^.+\\.jsx?$": "babel-jest"
},
```

View File

@@ -0,0 +1,131 @@
'use strict'; /**
* 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.
*
*
*/
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
const jestPreset = require('babel-preset-jest');
const BABELRC_FILENAME = '.babelrc';
const BABELRC_JS_FILENAME = '.babelrc.js';
const BABEL_CONFIG_KEY = 'babel';
const PACKAGE_JSON = 'package.json';
const THIS_FILE = fs.readFileSync(__filename);
let babel;
const createTransformer = options => {
const cache = Object.create(null);
const getBabelRC = filename => {
const paths = [];
let directory = filename;
while (directory !== (directory = path.dirname(directory))) {
if (cache[directory]) {
break;
}
paths.push(directory);
const configFilePath = path.join(directory, BABELRC_FILENAME);
if (fs.existsSync(configFilePath)) {
cache[directory] = fs.readFileSync(configFilePath, 'utf8');
break;
}
const configJsFilePath = path.join(directory, BABELRC_JS_FILENAME);
if (fs.existsSync(configJsFilePath)) {
// $FlowFixMe
cache[directory] = JSON.stringify(require(configJsFilePath));
break;
}
const packageJsonFilePath = path.join(directory, PACKAGE_JSON);
if (fs.existsSync(packageJsonFilePath)) {
// $FlowFixMe
const packageJsonFileContents = require(packageJsonFilePath);
if (packageJsonFileContents[BABEL_CONFIG_KEY]) {
cache[directory] = JSON.stringify(
packageJsonFileContents[BABEL_CONFIG_KEY]);
break;
}
}
}
paths.forEach(directoryPath => cache[directoryPath] = cache[directory]);
return cache[directory] || '';
};
options = Object.assign({}, options, {
plugins: options && options.plugins || [],
presets: (options && options.presets || []).concat([jestPreset]),
retainLines: true });
delete options.cacheDirectory;
delete options.filename;
return {
canInstrument: true,
getCacheKey(
fileData,
filename,
configString, _ref)
{let instrument = _ref.instrument;
return crypto.
createHash('md5').
update(THIS_FILE).
update('\0', 'utf8').
update(fileData).
update('\0', 'utf8').
update(configString).
update('\0', 'utf8').
update(getBabelRC(filename)).
update('\0', 'utf8').
update(instrument ? 'instrument' : '').
digest('hex');
},
process(
src,
filename,
config,
transformOptions)
{
if (!babel) {
babel = require('babel-core');
}
if (babel.util && !babel.util.canCompile(filename)) {
return src;
}
const theseOptions = Object.assign({ filename }, options);
if (transformOptions && transformOptions.instrument) {
theseOptions.auxiliaryCommentBefore = ' istanbul ignore next ';
// Copied from jest-runtime transform.js
theseOptions.plugins = theseOptions.plugins.concat([
[
require('babel-plugin-istanbul').default,
{
// files outside `cwd` will not be instrumented
cwd: config.rootDir,
exclude: [] }]]);
}
return babel.transform(src, theseOptions).code;
} };
};
module.exports = createTransformer();
module.exports.createTransformer = createTransformer;

View File

@@ -0,0 +1,49 @@
{
"_args": [
[
"babel-jest@20.0.3",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "babel-jest@20.0.3",
"_id": "babel-jest@20.0.3",
"_inBundle": false,
"_integrity": "sha1-5KA7E9wQOJ4UD8ZF0J/8TO0wFnE=",
"_location": "/react-scripts/babel-jest",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "babel-jest@20.0.3",
"name": "babel-jest",
"escapedName": "babel-jest",
"rawSpec": "20.0.3",
"saveSpec": null,
"fetchSpec": "20.0.3"
},
"_requiredBy": [
"/react-scripts",
"/react-scripts/jest-runtime"
],
"_resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-20.0.3.tgz",
"_spec": "20.0.3",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"bugs": {
"url": "https://github.com/facebook/jest/issues"
},
"dependencies": {
"babel-core": "^6.0.0",
"babel-plugin-istanbul": "^4.0.0",
"babel-preset-jest": "^20.0.3"
},
"description": "Jest plugin to use babel for transformation.",
"homepage": "https://github.com/facebook/jest#readme",
"license": "BSD-3-Clause",
"main": "build/index.js",
"name": "babel-jest",
"repository": {
"type": "git",
"url": "git+https://github.com/facebook/jest.git"
},
"version": "20.0.3"
}