Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(babel-jest): wrap babel-jest to support conventions
- Loading branch information
Showing
12 changed files
with
1,345 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
extends: ['../../.eslintrc.js'], | ||
rules: { | ||
'import/no-nodejs-modules': 'off' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Change Log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2010 - 2018 Blue Spire Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lernajs.io/) | ||
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/) | ||
[![CircleCI](https://circleci.com/gh/aurelia/aurelia.svg?style=shield)](https://circleci.com/gh/aurelia/aurelia) | ||
[![Test Coverage](https://api.codeclimate.com/v1/badges/5ac0e13689735698073a/test_coverage)](https://codeclimate.com/github/aurelia/aurelia/test_coverage) | ||
[![npm](https://img.shields.io/npm/v/@aurelia/babel-jest.svg?maxAge=3600)](https://www.npmjs.com/package/@aurelia/babel-jest) | ||
# @aurelia/babel-jest | ||
|
||
## Installing | ||
|
||
For the latest stable version: | ||
|
||
```bash | ||
npm i -D @aurelia/babel-jest | ||
``` | ||
|
||
For our nightly builds: | ||
|
||
```bash | ||
npm i -D @aurelia/babel-jest@dev | ||
``` | ||
|
||
## Usage | ||
|
||
In `jest.config.js` or `package.json`: | ||
|
||
```js | ||
"transform": { | ||
"^.+\\.js$": "@aurelia/babel-jest" | ||
} | ||
``` | ||
|
||
Use ShadowDOM: | ||
|
||
```js | ||
"transform": { | ||
"^.+\\.js$": ["@aurelia/babel-jest", { defaultShadowOptions: { mode: 'open' } }] | ||
} | ||
``` | ||
|
||
Use CSS Modules: | ||
|
||
```js | ||
"transform": { | ||
"^.+\\.js$": ["@aurelia/babel-jest", { useCSSModule: true }] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "@aurelia/babel-jest", | ||
"version": "0.6.0", | ||
"main": "dist/esnext/index.js", | ||
"module": "dist/esnext/index.js", | ||
"types": "dist/index.d.ts", | ||
"typings": "dist/index.d.ts", | ||
"license": "MIT", | ||
"homepage": "https://aurelia.io", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/aurelia/aurelia" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/aurelia/aurelia/issues" | ||
}, | ||
"keywords": [ | ||
"aurelia", | ||
"jest" | ||
], | ||
"files": [ | ||
"dist", | ||
"src", | ||
"README.md", | ||
"CHANGELOG.md", | ||
"LICENSE" | ||
], | ||
"scripts": { | ||
"lint": "eslint --cache --ext .js,.ts src/", | ||
"build": "tsc -b", | ||
"bundle": "ts-node -P ../../tsconfig.json ../../scripts/bundle.ts umd,esm,system babel-jest", | ||
"dev": "tsc -b -w" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@aurelia/plugin-conventions": "0.6.0", | ||
"babel-jest": "^25.3.0" | ||
}, | ||
"devDependencies": { | ||
"@jest/transform": "^25.3.0", | ||
"@jest/types": "^25.3.0", | ||
"@types/node": "^12.12.21", | ||
"tslib": "^1.10.0", | ||
"typescript": "^3.7.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { IOptionalPreprocessOptions, preprocess, preprocessOptions } from '@aurelia/plugin-conventions'; | ||
import { createTransformer } from 'babel-jest'; | ||
import type { Config } from '@jest/types'; | ||
import type { TransformOptions, Transformer } from '@jest/transform'; | ||
import * as path from 'path'; | ||
|
||
const transformer = createTransformer(); | ||
const { process } = transformer; | ||
|
||
function newProcess( | ||
sourceText: string, | ||
sourcePath: Config.Path, | ||
config: Config.ProjectConfig, | ||
transformOptions?: TransformOptions | ||
) { | ||
try { | ||
const allOptions = preprocessOptions((transformOptions as IOptionalPreprocessOptions) || {}); | ||
const result = preprocess( | ||
{ path: sourcePath, contents: sourceText }, | ||
allOptions | ||
); | ||
let newSourcePath = sourcePath; | ||
if (result !== undefined) { | ||
if (allOptions.templateExtensions.includes(path.extname(sourcePath))) { | ||
// Rewrite foo.html to foo.html.js, or foo.md to foo.md.js | ||
newSourcePath += '.js'; | ||
} | ||
// TODO: to check. This might have complication on jest caches. | ||
return process(result.code, newSourcePath, config, transformOptions); | ||
} | ||
} catch (e) { | ||
// ignore | ||
} | ||
return process(sourceText, sourcePath, config, transformOptions); | ||
} | ||
|
||
transformer.process = newProcess; | ||
export = transformer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../tsconfig-build.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"declarationDir": "dist", | ||
"outDir": "dist/esnext" | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters