Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gasket-jest-plugin #24

Merged
merged 3 commits into from
Jul 23, 2019
Merged
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
4 changes: 4 additions & 0 deletions packages/gasket-jest-plugin/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
"extends": ["godaddy-react", "plugin:jest/recommended"],
"parser": "babel-eslint"
};
1 change: 1 addition & 0 deletions packages/gasket-jest-plugin/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock.json binary
65 changes: 65 additions & 0 deletions packages/gasket-jest-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Logs (npm-debug.log, yarn-error.log, etc)
logs
*.log

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional next cache directory
.next
pages

# OSX Finder cache files
.DS_Store

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# Editor files
.idea
*.iml

lib
71 changes: 71 additions & 0 deletions packages/gasket-jest-plugin/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Logs (npm-debug.log, yarn-error.log, etc)
logs
*.log

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional next cache directory
.next
pages

# OSX Finder cache files
.DS_Store

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# Editor files
.idea
*.iml

### ▲ .gitignore contents above
### ▼ additional ignore files for publishing

test/*
.eslintrc.js
.gitattributes
Jenkinsfile
9 changes: 9 additions & 0 deletions packages/gasket-jest-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# CHANGELOG

### 1.1.0

- Upgrades to dependencies in create hook.

### 1.0.0

- Initial release.
21 changes: 21 additions & 0 deletions packages/gasket-jest-plugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2019 GoDaddy Operating Company, LLC.

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.
26 changes: 26 additions & 0 deletions packages/gasket-jest-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# jest-plugin

Creates a `jest` with `enzyme` based testing environment for your Gasket application.

## Installation

```
gasket create APPNAME --plugins jest
```

## Usage

When you create a new gasket application that is configured with the `jest`
plugin it will prepare it with a `jest` based testing environment. It will
add the following `scripts` to the `package.json`:

- `npm test`, Runs the files matching default jest glob pattern, i.e. includes files
from __tests__ folder and all `*.test.js` or `*.spec.js` files.
- `npm run test:watch` Same as `npm test` but now watches your tests
and automatically re-runs the tests when changes are detected.
- `npm run test:coverage` Same as `npm test`, but generates coverage information for all the
files matching the `collectCoverageFrom` pattern in `jest.config.js` file.

`enzyme` is included with this plugin, which makes it easier to assert, manipulate, and traverse your React Components.

##### LICENSE: [MIT](./LICENSE)
5 changes: 5 additions & 0 deletions packages/gasket-jest-plugin/generator/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
setupFiles: ['./test/setup.js'],
collectCoverageFrom: ['**/*.js'],
testURL: 'http://localhost/'
};
12 changes: 12 additions & 0 deletions packages/gasket-jest-plugin/generator/test/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { shallow } from 'enzyme';
import { IndexPage } from '../pages/index';
import Head from '../components/head';

describe('IndexPage', () => {
it('shallow renders', () => {
const wrapper = shallow(<IndexPage />);
expect(wrapper.find(Head)).toHaveLength(1);
});
});

5 changes: 5 additions & 0 deletions packages/gasket-jest-plugin/generator/test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

// React 16 Enzyme adapter
Enzyme.configure({ adapter: new Adapter() });
30 changes: 30 additions & 0 deletions packages/gasket-jest-plugin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
name: 'jest',
hooks: {
async create(gasket, { files, pkg }) {
const path = require('path');

files.add(
path.join(__dirname, 'generator', '*'),
path.join(__dirname, 'generator', '**', '*')
);

pkg.add('devDependencies', {
'jest': '^23.4.2',
'enzyme': '^3.8.0',
'enzyme-adapter-react-16': '^1.8.0',
'eslint-plugin-jest': '^22.2.2'
});

pkg.add('scripts', {
'test': 'jest',
'test:watch': 'jest --watchAll',
'test:coverage': 'jest --coverage'
});

pkg.add('eslintConfig', {
extends: ['plugin:jest/recommended']
});
}
}
};
5 changes: 5 additions & 0 deletions packages/gasket-jest-plugin/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
collectCoverageFrom: ['**/*.js'],
testURL: 'http://localhost/',
testMatch: ['**/test/*.test.js']
};
51 changes: 51 additions & 0 deletions packages/gasket-jest-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@gasket/jest-plugin",
"version": "1.1.0",
"description": "Integrated jest into your application.",
"main": "index.js",
"scripts": {
"lint": "eslint *.js generator/*.js generator/**/*.js",
"lint:fix": "npm run lint -- --fix",
"pretest": "npm run lint",
"test": "jest",
"test:watch": "jest --watchAll",
"test:coverage": "jest --coverage"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/godaddy/gasket"
},
"maintainers": [
"Salil Agrawal <sagrawal@godaddy.com>",
"Andrew Gerard <agerard@godaddy.com>"
],
"homepage": "https://github.com/godaddy/gasket/tree/master/packages/gasket-jest-plugin",
"author": "GoDaddy Operating Company, LLC",
"keywords": [
"jest",
"gasket",
"plugin"
],
"license": "MIT",
"devDependencies": {
"babel-eslint": "^10.0.1",
"babel-preset-env": "^1.7.0",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.8.0",
"eslint": "^5.16.0",
"eslint-config-godaddy-react": "^4.1.0",
"eslint-plugin-jest": "^22.2.2",
"eslint-plugin-json": "^1.2.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-mocha": "^5.3.0",
"eslint-plugin-react": "^7.12.4",
"jest": "^23.4.2",
"react": "^16.4.2",
"react-dom": "^16.4.2"
},
"babel": {
"presets": [
"babel-preset-env"
]
}
}
Loading