Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
pghalliday committed Mar 17, 2017
0 parents commit b18e4d2
Show file tree
Hide file tree
Showing 14 changed files with 336 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Test against the latest version of this Node.js version
environment:
nodejs_version: "6"

# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install

# Post-install test scripts.
test_script:
# Output useful info for debugging.
- node --version
- npm --version
# run tests
- npm run build

# Don't actually build.
build: off
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": ["env"],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
}
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules/
/coverage/
/lib/
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
extends: 'google',
env: {
node: true,
es6: true
},
rules: {
'no-unused-vars': [2, {'args': 'after-used', 'argsIgnorePattern': '^_', 'varsIgnorePattern': '^_'}],
'require-jsdoc': 0
},
parserOptions: {
ecmaVersion: 8,
sourceType: 'module'
}
};
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.alarmist/
/npm-debug.log
/node_modules/
/coverage/
/.nyc_output/
.DS_Store
21 changes: 21 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"check-coverage": false,
"lines": 100,
"statements": 100,
"functions": 100,
"branches": 100,
"watermarks": {
"lines": [100, 100],
"statements": [100, 100],
"functions": [100, 100],
"branches": [100, 100]
},
"reporter": [
"lcov"
],
"require": [
"babel-register"
],
"sourceMap": false,
"instrument": false
}
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- '5'
- '6'
- 'stable'
script: npm run ci
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# forgiven-webcomponents

[![Build Status](https://travis-ci.org/pghalliday/forgiven-webcomponents.svg?branch=master)](https://travis-ci.org/pghalliday/forgiven-webcomponents)
[![Build status](https://ci.appveyor.com/api/projects/status/8jaac5m0tgfwf283/branch/master?svg=true)](https://ci.appveyor.com/project/pghalliday/forgiven-webcomponents/branch/master)
[![Coverage Status](https://coveralls.io/repos/github/pghalliday/forgiven-webcomponents/badge.svg?branch=master)](https://coveralls.io/github/pghalliday/forgiven-webcomponents?branch=master)

[Forgiven](https://www.npmjs.com/package/forgiven) extensions for [web-component-tester](https://github.com/Polymer/web-component-tester) test-fixtures

## Usage

```shell
npm install --save-dev web-component-tester forgiven forgiven-mocha forgiven-webcomponents
```

```javascript
import {
create,
} from 'forgiven';
import {
mocha,
} from 'forgiven-mocha';
import {
webcomponents,
} from 'forgiven-webcomponents';

global.given = create(mocha, {
fixture: webcomponents,
});
```

## Contributing

Run unit tests and build before pushing/opening a pull request.

- `npm test` - lint and test
- `npm start` - watch and build, etc with alarmist
- `npm run build` - run tests then build
- `npm run watch` - watch for changes and run build
- `npm run ci` - run build and submit coverage to coveralls
70 changes: 70 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.webcomponents = webcomponents;

var _forgiven = require('forgiven');

function webcomponents(setup) {
return {
as: function as(context, name) {
var setupFixture = function setupFixture(conjunction, id, data) {
return setup({
description: 'as `' + name + '` ' + conjunction + ' ' + id,
beforeEach: function beforeEach(done) {
var element = document.getElementbyId(id).create(data);
element.record = {
event: function event(_event) {
return {
as: function as(name) {
element.addEventListener(_event, function (event) {
context[name] = event;
});
}
};
},
events: function events(event) {
return {
as: function as(name) {
context[name] = [];
element.addEventListener(event, function (event) {
context[name].push(event);
});
}
};
}
};
element.promise = {
event: function event(_event2) {
return {
as: function as(name) {
context[name] = new Promise(function (resolve) {
var listener = function listener(evt) {
element.removeEventListener(_event2, listener);
resolve(evt);
};
element.addEventListener(_event2, listener);
});
}
};
}
};
context[name] = element;
flush(done);
},
afterEach: function afterEach(done) {
context[name].restore();
flush(done);
}
});
};
var chain = {};
_forgiven.SETUP_CONJUNCTIONS.forEach(function (conjunction) {
chain[conjunction] = setupFixture.bind(null, conjunction);
});
return next;
}
};
};
54 changes: 54 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "forgiven-webcomponents",
"version": "0.0.0",
"description": "Forgiven extensions for web-component-tester test-fixtures",
"main": "lib/index.js",
"scripts": {
"cmd:lint": "eslint .",
"cmd:test": "cross-env NODE_ENV=test nyc mocha",
"cmd:coverage": "nyc report -r text",
"cmd:build": "babel src --out-dir lib",
"cmd:coveralls": "cat ./coverage/lcov.info | coveralls",
"test": "run-s cmd:lint cmd:test cmd:coverage",
"build": "run-s test cmd:build",
"ci": "run-s build cmd:coveralls",
"alarmist:lint": "chokidar \"+(src|test)/**/*\" -c \"alarmist-npm cmd:lint\"",
"alarmist:test": "chokidar \"+(src|test)/**/*\" -c \"alarmist-npm cmd:test\"",
"alarmist:coverage": "chokidar \"coverage/lcov.info\" -c \"alarmist-npm cmd:coverage\"",
"alarmist:build": "chokidar \"src/**/*\" -c \"alarmist-npm cmd:build\"",
"start": "alarmist-monitor run-p alarmist:lint alarmist:test alarmist:coverage alarmist:build",
"watch": "chokidar '+(src|test)/**/*' -c 'npm run -s build'",
"prepublish": "run-s cmd:build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pghalliday/forgiven-webcomponents.git"
},
"keywords": [],
"author": "Peter Halliday <pghalliday@gmail.com> (http://pghalliday.com)",
"license": "ISC",
"bugs": {
"url": "https://github.com/pghalliday/forgiven-webcomponents/issues"
},
"homepage": "https://github.com/pghalliday/forgiven-webcomponents#readme",
"devDependencies": {
"alarmist": "^1.0.17",
"alarmist-npm": "^1.0.4",
"babel-cli": "^6.22.2",
"babel-plugin-istanbul": "^3.1.2",
"babel-preset-env": "^1.1.8",
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"chokidar-cli": "^1.2.0",
"coveralls": "^2.11.15",
"cross-env": "^3.1.4",
"eslint": "^3.14.1",
"eslint-config-google": "^0.7.1",
"forgiven": "0.0.1",
"mocha": "^3.2.0",
"npm-run-all": "^4.0.1",
"nyc": "^10.1.2",
"sinon": "^2.0.0",
"sinon-chai": "^2.8.0"
}
}
65 changes: 65 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {
SETUP_CONJUNCTIONS,
} from 'forgiven';

export function webcomponents(setup) {
return {
as: function(context, name) {
const setupFixture = (conjunction, id, data) => {
return setup({
description: 'as `' + name + '` ' + conjunction + ' ' + id,
beforeEach: (done) => {
const element = document.getElementbyId(id).create(data);
element.record = {
event: (event) => {
return {
as: (name) => {
element.addEventListener(event, (event) => {
context[name] = event;
});
},
};
},
events: (event) => {
return {
as: (name) => {
context[name] = [];
element.addEventListener(event, (event) => {
context[name].push(event);
});
},
};
},
};
element.promise = {
event: (event) => {
return {
as: (name) => {
context[name] = new Promise((resolve) => {
const listener = (evt) => {
element.removeEventListener(event, listener);
resolve(evt);
};
element.addEventListener(event, listener);
});
},
};
},
};
context[name] = element;
flush(done);
},
afterEach: (done) => {
context[name].restore();
flush(done);
},
});
};
const chain = {};
SETUP_CONJUNCTIONS.forEach((conjunction) => {
chain[conjunction] = setupFixture.bind(null, conjunction);
});
return next;
},
};
};
3 changes: 3 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test/src
--recursive
--require test/setup
13 changes: 13 additions & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// polyfills
import 'babel-polyfill';

// assertions
import chai from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import chaiAsPromised from 'chai-as-promised';
chai.use(sinonChai);
chai.use(chaiAsPromised);
chai.should();
global.expect = chai.expect;
global.sinon = sinon;
12 changes: 12 additions & 0 deletions test/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {
webcomponents,
} from '../../src';

describe('forgiven-webcomponents', () => {
it('should export the webcomponents plugin', () => {
webcomponents.should.be.ok;
});

// TODO: this is an initial import of something that was working
// more integration tests need to be created
});

0 comments on commit b18e4d2

Please sign in to comment.