Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Added examples to the main repo and added tests steps making sure the…
Browse files Browse the repository at this point in the history
…y work (#23)

* docs: Added examples to the main repo and added tests steps making sure they work

* doc: Removed examples

* docs: Added back examples folder

* Change to travis to build master only
  • Loading branch information
adriantoine authored Sep 7, 2016
1 parent 08a43e2 commit f07d3fe
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ indent_size = 4
end_of_line = lf
charset = utf-8

[package.json]
[package.json,.yml]
indent_size = 2
19 changes: 11 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ language: node_js

cache:
directories:
- node_modules
- node_modules

node_js:
- 6
- 4
- 6
- 4

before_install:
- npm i -g npm@latest
- npm i -g npm@latest

before_script:
- npm prune
- npm prune

script:
- npm run lint
- npm test
- npm test

after_success:
- './node_modules/.bin/nyc report --reporter=lcov > coverage.lcov && ./node_modules/.bin/codecov'
- './node_modules/.bin/nyc report --reporter=lcov > coverage.lcov && ./node_modules/.bin/codecov'

branches:
only:
- master
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This Babel 6 plugin allows you to use webpack aliases in Babel.

This plugin is simply going to take the aliases defined in your webpack config and replace require paths. It is especially useful when you rely on webpack aliases to keep require paths nicer (and sometimes more consistent depending on your project configuration) but you can't use webpack in a context, for example for unit testing.

If you are having issues while making this plugin work, have a look at the [babel-plugin-webpack-alias-examples](https://github.com/adriantoine/babel-plugin-webpack-alias-examples) repo. Play with it, mix your own config in, and feel free to [open an issue](https://github.com/trayio/babel-plugin-webpack-alias/issues/new)!
If you are having issues while making this plugin work, have a look at the [examples](/examples) folder. Play with them, mix your own config in, and feel free to [open an issue](https://github.com/trayio/babel-plugin-webpack-alias/issues/new)!

## Example
With the following `webpack.config.js`:
Expand Down
10 changes: 10 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Examples for babel-plugin-webpack-alias

This is there to demonstrate how to use [`babel-plugin-webpack-alias`](https://github.com/trayio/babel-plugin-webpack-alias) with popular testing frameworks.

These examples are as minimal as possible, they work just by running the command:
```console
$ npm install && npm test
```

If your own configuration of [`babel-plugin-webpack-alias`](https://github.com/trayio/babel-plugin-webpack-alias) doesn't work, you can clone this repo and play with the examples.
6 changes: 6 additions & 0 deletions examples/ava/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": ["es2015"],
"plugins": [
["webpack-alias", {"config": "${PWD}/webpack.config.js"}]
]
}
5 changes: 5 additions & 0 deletions examples/ava/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Just run:

```console
$ npm install && npm test
```
3 changes: 3 additions & 0 deletions examples/ava/add10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import sum from 'alias/sum';

export default num => sum(num, 10);
1 change: 1 addition & 0 deletions examples/ava/deep/folder/alias/sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default (a, b) => a + b;
22 changes: 22 additions & 0 deletions examples/ava/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "babel-plugin-webpack-alias-ava",
"version": "1.0.0",
"description": "babel-plugin-webpack-alias example with AVA",
"scripts": {
"test": "PWD=$(pwd) ava"
},
"keywords": [],
"author": "Adrien Antoine <[email protected]> (http://tray.io)",
"license": "ISC",
"devDependencies": {
"ava": "^0.16.0",
"babel-plugin-webpack-alias": "../..",
"babel-preset-es2015": "^6.14.0",
"babel-register": "^6.14.0"
},
"ava": {
"require": [
"babel-register"
]
}
}
6 changes: 6 additions & 0 deletions examples/ava/test/add10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import add10 from '../add10';
import test from 'ava';

test('should test add10 without errors', t => {
t.is(add10(5), 15);
});
9 changes: 9 additions & 0 deletions examples/ava/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var path = require('path');

module.exports = {
resolve: {
alias: {
'alias': path.join(__dirname, 'deep/folder/alias'),
}
}
};
4 changes: 4 additions & 0 deletions examples/mocha/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["webpack-alias"]
}
5 changes: 5 additions & 0 deletions examples/mocha/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Just run:

```console
$ npm install && npm test
```
3 changes: 3 additions & 0 deletions examples/mocha/add10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import sum from 'alias/sum';

export default num => sum(num, 10);
1 change: 1 addition & 0 deletions examples/mocha/deep/folder/alias/sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default (a, b) => a + b;
18 changes: 18 additions & 0 deletions examples/mocha/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "babel-plugin-webpack-alias-mocha",
"version": "1.0.0",
"description": "babel-plugin-webpack-alias example with mocha",
"scripts": {
"test": "mocha --compilers js:babel-register"
},
"keywords": [],
"author": "Adrien Antoine <[email protected]> (http://tray.io)",
"license": "ISC",
"devDependencies": {
"babel-plugin-webpack-alias": "../..",
"babel-preset-es2015": "^6.14.0",
"babel-register": "^6.14.0",
"chai": "^3.5.0",
"mocha": "^3.0.2"
}
}
8 changes: 8 additions & 0 deletions examples/mocha/test/add10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import add10 from '../add10';
import { expect } from 'chai';

describe('alias test', () => {
it('should test add10 without errors', () => {
expect(add10(5)).to.equal(15);
});
});
9 changes: 9 additions & 0 deletions examples/mocha/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var path = require('path');

module.exports = {
resolve: {
alias: {
'alias': path.join(__dirname, 'deep/folder/alias'),
}
}
};
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
"scripts": {
"build": "babel src -d build",
"dev": "watch 'npm run build' src/",
"lint": "eslint src/ test/",
"test": "nyc --cache --reporter=text ava",
"test": "npm run test:lint && npm run test:plugin && npm run test:ava && npm run test:mocha",
"test:lint": "eslint src/ test/",
"test:plugin": "eslint src/ test/ && nyc --cache --reporter=text ava",
"test:ava": "cd examples/ava; rm -rf node_modules; npm it",
"test:mocha": "cd examples/mocha; rm -rf node_modules; npm it",
"prepublish": "npm run build"
},
"license": "ISC",
Expand Down

0 comments on commit f07d3fe

Please sign in to comment.