Skip to content

Commit

Permalink
migrate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kof committed Nov 16, 2016
1 parent 25a0d67 commit cc93918
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 105 deletions.
6 changes: 5 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"presets": ["stage-0", "es2015"]
"presets": ["es2015", "stage-0"],
"plugins": [
"transform-es3-member-expression-literals",
"transform-es3-property-literals"
]
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
node_modules
.DS_Store
npm-debug.log
tmp
*~
lib
dist
coverage
tests
tmp
3 changes: 1 addition & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
src
bench
coverage
tmp
test
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright (c) 2008-present Oleg Slobodskoi
Copyright (c) 2014-present Oleg Slobodskoi

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:

Expand Down
19 changes: 19 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const webpackConfig = require('./webpack.config')

module.exports = (config) => {
config.set({
browsers: ['Chrome'],
frameworks: ['mocha'],
files: ['tests.webpack.js'],
preprocessors: {
'tests.webpack.js': ['webpack', 'sourcemap']
},
webpack: Object.assign(webpackConfig, {
devtool: 'inline-source-map'
}),
webpackServer: {
noInfo: true
},
reporters: ['mocha']
})
}
59 changes: 39 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,58 @@
],
"engines": {},
"scripts": {
"all": "npm run lint && npm run build",
"build": "npm run clean && npm run build:lib && npm run build:max && npm run build:min",
"all": "npm run lint && npm run test && npm run build",
"build": "npm run clean && npm run build:lib && npm run build:tests && npm run build:dist",
"build:lib": "babel src --out-dir lib",
"build:max": "cross-env NODE_ENV=development webpack src/index.js dist/css-vendor.js",
"build:min": "cross-env NODE_ENV=production webpack src/index.js dist/css-vendor.min.js",
"clean": "rimraf ./lib/*",
"build:tests": "npm run build:tests:lib && npm run build:tests:local",
"build:tests:lib": "cross-env NODE_ENV=test babel src --out-dir tests",
"build:tests:local": "cross-env NODE_ENV=test webpack src/index.test.js tmp/tests.js",
"build:dist": "npm run build:dist:max && npm run build:dist:min",
"build:dist:max": "cross-env NODE_ENV=development webpack src/index.js dist/react-jss.js",
"build:dist:min": "cross-env NODE_ENV=production webpack src/index.js dist/react-jss.min.js",
"clean": "rimraf {lib,dist,tests,tmp}/*",
"lint": "eslint ./src",
"lint:staged": "lint-staged",
"test": "opener ./test/index.html",
"test": "cross-env NODE_ENV=test karma start --single-run ",
"test:watch": "cross-env NODE_ENV=test karma start",
"prepublish": "npm run all"
},
"license": "MIT",
"main": "./lib/index",
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-core": "^6.5.1",
"babel-eslint": "^7.0.0",
"babel-loader": "^6.2.2",
"babel-preset-es2015": "^6.5.0",
"babel-eslint": "^6.1.2",
"babel-loader": "^6.2.4",
"babel-plugin-transform-es3-member-expression-literals": "^6.8.0",
"babel-plugin-transform-es3-property-literals": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"cross-env": "^3.1.3",
"eslint": "^3.8.0",
"eslint-config-airbnb": "^12.0.0",
"eslint-config-jss": "^2.4.0",
"eslint-plugin-import": "^2.0.1",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.4.1",
"jss": "^5.4.0",
"opener": "^1.4.1",
"es5-shim": "^4.5.9",
"eslint": "^2.8.0",
"eslint-config-airbnb": "^8.0.0",
"eslint-config-jss": "^1.1.0",
"eslint-plugin-import": "^1.12.0",
"eslint-plugin-jsx-a11y": "^1.5.5",
"eslint-plugin-react": "^5.0.1",
"expect.js": "^0.3.1",
"karma": "^1.1.1",
"karma-benchmark": "^0.6.0",
"karma-benchmark-reporter": "^0.1.1",
"karma-browserstack-launcher": "^1.0.0",
"karma-chrome-launcher": "^1.0.1",
"karma-firefox-launcher": "^1.0.0",
"karma-mocha": "^1.0.1",
"karma-mocha-reporter": "^2.0.2",
"karma-safari-launcher": "^1.0.0",
"karma-sourcemap-loader": "^0.3.5",
"karma-webpack": "^1.7.0",
"lint-staged": "^3.0.1",
"mocha": "^3.0.2",
"pre-commit": "^1.1.3",
"qunitjs": "2.0.1",
"rimraf": "^2.5.1",
"webpack": "^2.0.7-beta"
"rimraf": "^2.5.4",
"webpack": "^1.12.2"
},
"dependencies": {
"is-in-browser": "^1.0.2"
Expand Down
62 changes: 62 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import expect from 'expect.js'

import {prefix, supportedProperty, supportedValue} from './index'

describe('css-vendor', () => {
describe('.prefix', () => {
it('should be correct for .css', () => {
const {css} = prefix
expect(css).to.be.a('string')
expect(css[0]).to.be('-')
expect(css[css.length - 1]).to.be('-')
expect(css.length >= 3).to.be(true)
})

it('shoud be not empty for .js', () => {
expect(prefix.js).to.be.a('string')
})
})

describe('.supportedProperty()', () => {
it('should not prefix', () => {
expect(supportedProperty('display')).to.be('display')
})

it('should prefix if needed', () => {
const prop = supportedProperty(`${prefix.css}animation`)
if (prop !== 'animation') {
expect(prop).to.be(`${prefix.css}animation`)
}
})

it('should return false', () => {
expect(supportedProperty('xxx')).to.be(false)
})
})

describe('.supportedValue()', () => {
it('should not prefix a simple value', () => {
expect(supportedValue('display', 'none')).to.be('none')
})

it('should not prefix a complex value', () => {
const value = 'rgba(255, 255, 255, 1.0)'
expect(supportedValue('color', value)).to.be(value)
})

it('should should prefix if needed', () => {
const value = supportedValue('display', 'flex')
if (value !== 'flex') {
expect(value).to.be(`${prefix.css}flex`)
}
})

it('should return false for unknown value', () => {
expect(supportedValue('display', 'xxx')).to.be(false)
})

it('should return false for "content" value', () => {
expect(supportedValue('content', 'bar')).to.be(false)
})
})
})
15 changes: 0 additions & 15 deletions test/index.html

This file was deleted.

61 changes: 0 additions & 61 deletions test/index.js

This file was deleted.

21 changes: 21 additions & 0 deletions tests.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>JSS Tests</title>
<link href="./node_modules/mocha/mocha.css" rel="stylesheet" />
</head>
<body>
<div id="mocha"></div>
<script src="./node_modules/es5-shim/es5-shim.js"></script>
<script src="./node_modules/mocha/mocha.js"></script>

<script>mocha.setup('bdd')</script>
<script src="tmp/tests.js"></script>
<script>
mocha.checkLeaks();
mocha.run();
</script>
</body>
</html>
2 changes: 2 additions & 0 deletions tests.webpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var context = require.context('./src', true, /\.test\.js$/)
context.keys().forEach(context)
6 changes: 2 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'
const webpack = require('webpack')

var webpack = require('webpack')

var plugins = [
const plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
__DEV__: process.env.NODE_ENV === 'development',
Expand Down

0 comments on commit cc93918

Please sign in to comment.