mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-02 02:25:22 +00:00
[change] Unit test setup and reporter
This commit is contained in:
@@ -3,9 +3,6 @@
|
|||||||
"parser": "babel-eslint",
|
"parser": "babel-eslint",
|
||||||
// based on https://github.com/feross/standard
|
// based on https://github.com/feross/standard
|
||||||
"extends": [ "standard", "standard-react" ],
|
"extends": [ "standard", "standard-react" ],
|
||||||
"env": {
|
|
||||||
"mocha": true
|
|
||||||
},
|
|
||||||
"rules": {
|
"rules": {
|
||||||
// overrides of the standard style
|
// overrides of the standard style
|
||||||
"space-before-function-paren": [ 2, { "anonymous": "always", "named": "never" } ],
|
"space-before-function-paren": [ 2, { "anonymous": "always", "named": "never" } ],
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "0.12"
|
- "4.1"
|
||||||
before_script:
|
before_script:
|
||||||
- export DISPLAY=:99.0
|
- export DISPLAY=:99.0
|
||||||
- sh -e /etc/init.d/xvfb start
|
- sh -e /etc/init.d/xvfb start
|
||||||
|
|||||||
+1
-1
@@ -70,7 +70,7 @@ Development commands:
|
|||||||
* `npm run build` – build the library
|
* `npm run build` – build the library
|
||||||
* `npm run dev` – start the dev server and develop against live examples
|
* `npm run dev` – start the dev server and develop against live examples
|
||||||
* `npm run lint` – run the linter
|
* `npm run lint` – run the linter
|
||||||
* `npm run test:specs` – run and watch the unit tests
|
* `npm run test` – run the linter and unit tests
|
||||||
|
|
||||||
Please follow this process for submitting a patch:
|
Please follow this process for submitting a patch:
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -5,5 +5,6 @@ var ROOT = path.join(__dirname, '..')
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
DIST_DIRECTORY: path.join(ROOT, 'dist'),
|
DIST_DIRECTORY: path.join(ROOT, 'dist'),
|
||||||
SRC_DIRECTORY: path.join(ROOT, 'src'),
|
SRC_DIRECTORY: path.join(ROOT, 'src'),
|
||||||
ROOT_DIRECTORY: ROOT
|
ROOT_DIRECTORY: ROOT,
|
||||||
|
TEST_ENTRY: path.join(ROOT, 'src/tests.webpack.js')
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-20
@@ -1,6 +1,5 @@
|
|||||||
var assign = require('object-assign')
|
|
||||||
var constants = require('./constants')
|
var constants = require('./constants')
|
||||||
var webpackConfig = require('./webpack.config.base')
|
var webpack = require('webpack')
|
||||||
|
|
||||||
module.exports = function (config) {
|
module.exports = function (config) {
|
||||||
config.set({
|
config.set({
|
||||||
@@ -9,38 +8,48 @@ module.exports = function (config) {
|
|||||||
browserNoActivityTimeout: 60000,
|
browserNoActivityTimeout: 60000,
|
||||||
client: {
|
client: {
|
||||||
captureConsole: true,
|
captureConsole: true,
|
||||||
mocha: {
|
mocha: { ui: 'tdd' },
|
||||||
ui: 'tdd'
|
|
||||||
},
|
|
||||||
useIframe: true
|
useIframe: true
|
||||||
},
|
},
|
||||||
files: [
|
files: [
|
||||||
'src/specs.context.js'
|
constants.TEST_ENTRY
|
||||||
],
|
|
||||||
frameworks: [
|
|
||||||
'mocha'
|
|
||||||
],
|
],
|
||||||
|
frameworks: [ 'mocha' ],
|
||||||
plugins: [
|
plugins: [
|
||||||
'karma-chrome-launcher',
|
'karma-chrome-launcher',
|
||||||
'karma-firefox-launcher',
|
'karma-firefox-launcher',
|
||||||
'karma-mocha',
|
'karma-mocha',
|
||||||
|
'karma-mocha-reporter',
|
||||||
'karma-sourcemap-loader',
|
'karma-sourcemap-loader',
|
||||||
'karma-webpack'
|
'karma-webpack'
|
||||||
],
|
],
|
||||||
preprocessors: {
|
preprocessors: {
|
||||||
'src/specs.context.js': [ 'webpack', 'sourcemap' ]
|
[constants.TEST_ENTRY]: [ 'webpack', 'sourcemap' ]
|
||||||
},
|
},
|
||||||
reporters: [ 'dots' ],
|
reporters: process.env.TRAVIS ? [ 'dots' ] : [ 'mocha' ],
|
||||||
singleRun: true,
|
singleRun: true,
|
||||||
webpack: assign({}, webpackConfig, { devtool: 'inline' }),
|
webpack: {
|
||||||
webpackMiddleware: {
|
devtool: 'inline-source-map',
|
||||||
stats: {
|
module: {
|
||||||
assetsSort: 'name',
|
loaders: [
|
||||||
colors: true,
|
{
|
||||||
children: false,
|
test: /\.js$/,
|
||||||
chunks: false,
|
exclude: /node_modules/,
|
||||||
modules: false
|
loader: 'babel',
|
||||||
}
|
query: { cacheDirectory: true }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
'process.env': {
|
||||||
|
NODE_ENV: JSON.stringify('test')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
},
|
||||||
|
webpackServer: {
|
||||||
|
noInfo: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-3
@@ -11,9 +11,9 @@
|
|||||||
"dev": "webpack-dev-server --config config/webpack.config.example.js --inline --colors --quiet",
|
"dev": "webpack-dev-server --config config/webpack.config.example.js --inline --colors --quiet",
|
||||||
"lint": "eslint config src",
|
"lint": "eslint config src",
|
||||||
"prepublish": "NODE_ENV=publish npm run build",
|
"prepublish": "NODE_ENV=publish npm run build",
|
||||||
"test:specs": "NODE_ENV=test karma start config/karma.config.js",
|
"test": "npm run lint && npm run test:unit",
|
||||||
"test:specs:watch": "npm run test:specs -- --no-single-run",
|
"test:unit": "karma start config/karma.config.js",
|
||||||
"test": "npm run test:specs && npm run lint"
|
"test:watch": "npm run test:unit -- --no-single-run"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": ">=0.13.3",
|
"react": ">=0.13.3",
|
||||||
@@ -35,9 +35,11 @@
|
|||||||
"eslint-plugin-standard": "^1.3.0",
|
"eslint-plugin-standard": "^1.3.0",
|
||||||
"extract-text-webpack-plugin": "^0.8.2",
|
"extract-text-webpack-plugin": "^0.8.2",
|
||||||
"karma": "^0.13.9",
|
"karma": "^0.13.9",
|
||||||
|
"karma-browserstack-launcher": "^0.1.5",
|
||||||
"karma-chrome-launcher": "^0.2.0",
|
"karma-chrome-launcher": "^0.2.0",
|
||||||
"karma-firefox-launcher": "^0.1.6",
|
"karma-firefox-launcher": "^0.1.6",
|
||||||
"karma-mocha": "^0.2.0",
|
"karma-mocha": "^0.2.0",
|
||||||
|
"karma-mocha-reporter": "^1.1.1",
|
||||||
"karma-sourcemap-loader": "^0.3.5",
|
"karma-sourcemap-loader": "^0.3.5",
|
||||||
"karma-webpack": "^1.7.0",
|
"karma-webpack": "^1.7.0",
|
||||||
"mocha": "^2.3.0",
|
"mocha": "^2.3.0",
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { assertProps, render, renderToDOM } from '../../modules/specHelpers'
|
/* eslint-env mocha */
|
||||||
|
|
||||||
|
import { assertProps, render, renderToDOM } from '../../../modules/specHelpers'
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import React from 'react/addons'
|
import React from 'react/addons'
|
||||||
|
|
||||||
import Image from '.'
|
import Image from '../'
|
||||||
|
|
||||||
suite('Image', () => {
|
suite('components/Image', () => {
|
||||||
test('default accessibility', () => {
|
test('default accessibility', () => {
|
||||||
const dom = renderToDOM(<Image />)
|
const dom = renderToDOM(<Image />)
|
||||||
assert.equal(dom.getAttribute('role'), 'img')
|
assert.equal(dom.getAttribute('role'), 'img')
|
||||||
@@ -18,7 +20,7 @@ suite('Image', () => {
|
|||||||
assertProps.accessible(Image)
|
assertProps.accessible(Image)
|
||||||
})
|
})
|
||||||
|
|
||||||
test.skip('prop "children"', () => { })
|
test('prop "children"')
|
||||||
|
|
||||||
test('prop "defaultSource"', () => {
|
test('prop "defaultSource"', () => {
|
||||||
const defaultSource = { uri: 'https://google.com/favicon.ico' }
|
const defaultSource = { uri: 'https://google.com/favicon.ico' }
|
||||||
@@ -51,13 +53,13 @@ suite('Image', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
test.skip('prop "onLoadEnd"', () => { })
|
test('prop "onLoadEnd"')
|
||||||
|
|
||||||
test.skip('prop "onLoadStart"', () => { })
|
test('prop "onLoadStart"')
|
||||||
|
|
||||||
test.skip('prop "resizeMode"', () => { })
|
test('prop "resizeMode"')
|
||||||
|
|
||||||
test.skip('prop "source"', () => { })
|
test('prop "source"')
|
||||||
|
|
||||||
test('prop "style"', () => {
|
test('prop "style"', () => {
|
||||||
assertProps.style(Image)
|
assertProps.style(Image)
|
||||||
+3
-1
@@ -1,8 +1,10 @@
|
|||||||
|
/* eslint-env mocha */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import React from 'react/addons'
|
import React from 'react/addons'
|
||||||
|
|
||||||
import ListView from '.'
|
import ListView from '../'
|
||||||
|
|
||||||
const ReactTestUtils = React.addons.TestUtils
|
const ReactTestUtils = React.addons.TestUtils
|
||||||
|
|
||||||
+3
-1
@@ -1,5 +1,7 @@
|
|||||||
|
/* eslint-env mocha */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
import { assertProps, renderToDOM, shallowRender } from '../../modules/specHelpers'
|
import { assertProps, renderToDOM, shallowRender } from '../../../modules/specHelpers'
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import React from 'react/addons'
|
import React from 'react/addons'
|
||||||
|
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
import { assertProps, renderToDOM, shallowRender } from '../../modules/specHelpers'
|
/* eslint-env mocha */
|
||||||
|
|
||||||
|
import { assertProps, renderToDOM, shallowRender } from '../../../modules/specHelpers'
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import React from 'react/addons'
|
import React from 'react/addons'
|
||||||
|
|
||||||
import Text from '.'
|
import Text from '../'
|
||||||
|
|
||||||
const ReactTestUtils = React.addons.TestUtils
|
const ReactTestUtils = React.addons.TestUtils
|
||||||
|
|
||||||
suite('Text', () => {
|
suite('components/Text', () => {
|
||||||
test('prop "accessibilityLabel"', () => {
|
test('prop "accessibilityLabel"', () => {
|
||||||
assertProps.accessibilityLabel(Text)
|
assertProps.accessibilityLabel(Text)
|
||||||
})
|
})
|
||||||
@@ -25,7 +27,7 @@ suite('Text', () => {
|
|||||||
assertProps.component(Text, 'span')
|
assertProps.component(Text, 'span')
|
||||||
})
|
})
|
||||||
|
|
||||||
test.skip('prop "numberOfLines"', () => {})
|
test('prop "numberOfLines"')
|
||||||
|
|
||||||
test('prop "onPress"', (done) => {
|
test('prop "onPress"', (done) => {
|
||||||
const dom = renderToDOM(<Text onPress={onPress} />)
|
const dom = renderToDOM(<Text onPress={onPress} />)
|
||||||
+29
-31
@@ -1,12 +1,14 @@
|
|||||||
import * as utils from '../../modules/specHelpers'
|
/* eslint-env mocha */
|
||||||
|
|
||||||
|
import * as utils from '../../../modules/specHelpers'
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import React from 'react/addons'
|
import React from 'react/addons'
|
||||||
|
|
||||||
import TextInput from '.'
|
import TextInput from '../'
|
||||||
|
|
||||||
const ReactTestUtils = React.addons.TestUtils
|
const ReactTestUtils = React.addons.TestUtils
|
||||||
|
|
||||||
suite('TextInput', () => {
|
suite('components/TextInput', () => {
|
||||||
test('prop "accessibilityLabel"', () => {
|
test('prop "accessibilityLabel"', () => {
|
||||||
utils.assertProps.accessibilityLabel(TextInput)
|
utils.assertProps.accessibilityLabel(TextInput)
|
||||||
})
|
})
|
||||||
@@ -29,18 +31,16 @@ suite('TextInput', () => {
|
|||||||
assert.deepEqual(document.activeElement, dom)
|
assert.deepEqual(document.activeElement, dom)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('prop "clearTextOnFocus"', () => {
|
utils.testIfDocumentFocused('prop "clearTextOnFocus"', () => {
|
||||||
const defaultValue = 'defaultValue'
|
const defaultValue = 'defaultValue'
|
||||||
utils.requiresFocus(() => {
|
// false
|
||||||
// false
|
let dom = utils.renderAndInject(<TextInput defaultValue={defaultValue} />)
|
||||||
let dom = utils.renderAndInject(<TextInput defaultValue={defaultValue} />)
|
dom.focus()
|
||||||
dom.focus()
|
assert.equal(dom.value, defaultValue)
|
||||||
assert.equal(dom.value, defaultValue)
|
// true
|
||||||
// true
|
dom = utils.renderAndInject(<TextInput clearTextOnFocus defaultValue={defaultValue} />)
|
||||||
dom = utils.renderAndInject(<TextInput clearTextOnFocus defaultValue={defaultValue} />)
|
dom.focus()
|
||||||
dom.focus()
|
assert.equal(dom.value, '')
|
||||||
assert.equal(dom.value, '')
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('prop "defaultValue"', () => {
|
test('prop "defaultValue"', () => {
|
||||||
@@ -126,7 +126,7 @@ suite('TextInput', () => {
|
|||||||
const height = dom.getBoundingClientRect().height
|
const height = dom.getBoundingClientRect().height
|
||||||
// need a range because of cross-browser differences
|
// need a range because of cross-browser differences
|
||||||
assert.ok(height >= 40)
|
assert.ok(height >= 40)
|
||||||
assert.ok(height <= 45)
|
assert.ok(height <= 46)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('prop "onBlur"', (done) => {
|
test('prop "onBlur"', (done) => {
|
||||||
@@ -166,7 +166,7 @@ suite('TextInput', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
test.skip('prop "onLayout"', () => {})
|
test('prop "onLayout"')
|
||||||
|
|
||||||
test('prop "onSelectionChange"', (done) => {
|
test('prop "onSelectionChange"', (done) => {
|
||||||
const input = utils.renderAndInject(<TextInput defaultValue='12345' onSelectionChange={onSelectionChange} />)
|
const input = utils.renderAndInject(<TextInput defaultValue='12345' onSelectionChange={onSelectionChange} />)
|
||||||
@@ -178,9 +178,9 @@ suite('TextInput', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
test.skip('prop "placeholder"', () => {})
|
test('prop "placeholder"')
|
||||||
|
|
||||||
test.skip('prop "placeholderTextColor"', () => {})
|
test('prop "placeholderTextColor"')
|
||||||
|
|
||||||
test('prop "secureTextEntry"', () => {
|
test('prop "secureTextEntry"', () => {
|
||||||
let dom = utils.renderToDOM(<TextInput secureTextEntry />)
|
let dom = utils.renderToDOM(<TextInput secureTextEntry />)
|
||||||
@@ -190,20 +190,18 @@ suite('TextInput', () => {
|
|||||||
assert.equal(dom.getAttribute('type'), undefined)
|
assert.equal(dom.getAttribute('type'), undefined)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('prop "selectTextOnFocus"', () => {
|
utils.testIfDocumentFocused('prop "selectTextOnFocus"', () => {
|
||||||
const text = 'Text'
|
const text = 'Text'
|
||||||
utils.requiresFocus(() => {
|
// false
|
||||||
// false
|
let dom = utils.renderAndInject(<TextInput defaultValue={text} />)
|
||||||
let dom = utils.renderAndInject(<TextInput defaultValue={text} />)
|
dom.focus()
|
||||||
dom.focus()
|
assert.equal(dom.selectionEnd, 0)
|
||||||
assert.equal(dom.selectionEnd, 0)
|
assert.equal(dom.selectionStart, 0)
|
||||||
assert.equal(dom.selectionStart, 0)
|
// true
|
||||||
// true
|
dom = utils.renderAndInject(<TextInput defaultValue={text} selectTextOnFocus />)
|
||||||
dom = utils.renderAndInject(<TextInput defaultValue={text} selectTextOnFocus />)
|
dom.focus()
|
||||||
dom.focus()
|
assert.equal(dom.selectionEnd, 4)
|
||||||
assert.equal(dom.selectionEnd, 4)
|
assert.equal(dom.selectionStart, 0)
|
||||||
assert.equal(dom.selectionStart, 0)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('prop "style"', () => {
|
test('prop "style"', () => {
|
||||||
+5
-3
@@ -1,13 +1,15 @@
|
|||||||
import { assertProps, shallowRender } from '../../modules/specHelpers'
|
/* eslint-env mocha */
|
||||||
|
|
||||||
|
import { assertProps, shallowRender } from '../../../modules/specHelpers'
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import React from 'react/addons'
|
import React from 'react/addons'
|
||||||
|
|
||||||
import Touchable from '.'
|
import Touchable from '../'
|
||||||
|
|
||||||
const children = <span style={{}}>children</span>
|
const children = <span style={{}}>children</span>
|
||||||
const requiredProps = { children }
|
const requiredProps = { children }
|
||||||
|
|
||||||
suite('Touchable', () => {
|
suite('components/Touchable', () => {
|
||||||
test('prop "accessibilityLabel"', () => {
|
test('prop "accessibilityLabel"', () => {
|
||||||
assertProps.accessibilityLabel(Touchable, requiredProps)
|
assertProps.accessibilityLabel(Touchable, requiredProps)
|
||||||
})
|
})
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
import { assertProps, shallowRender } from '../../modules/specHelpers'
|
/* eslint-env mocha */
|
||||||
|
|
||||||
|
import { assertProps, shallowRender } from '../../../modules/specHelpers'
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import React from 'react/addons'
|
import React from 'react/addons'
|
||||||
|
|
||||||
import View from '.'
|
import View from '../'
|
||||||
|
|
||||||
suite('View', () => {
|
suite('components/View', () => {
|
||||||
test('prop "accessibilityLabel"', () => {
|
test('prop "accessibilityLabel"', () => {
|
||||||
assertProps.accessibilityLabel(View)
|
assertProps.accessibilityLabel(View)
|
||||||
})
|
})
|
||||||
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
import { omitProps, pickProps } from '.'
|
/* eslint-env mocha */
|
||||||
|
|
||||||
|
import { omitProps, pickProps } from '..'
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
|
|
||||||
suite('pickProps', () => {
|
suite('pickProps', () => {
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
/* eslint-env mocha */
|
||||||
|
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import React from 'react/addons'
|
import React from 'react/addons'
|
||||||
|
|
||||||
@@ -105,19 +107,16 @@ export function renderToDOM(element, container) {
|
|||||||
return React.findDOMNode(result)
|
return React.findDOMNode(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function requiresFocus(test, fallback) {
|
|
||||||
if (document.hasFocus && document.hasFocus()) {
|
|
||||||
test()
|
|
||||||
} else {
|
|
||||||
console.warn('Test was skipped as the document is not focused')
|
|
||||||
if (fallback) {
|
|
||||||
fallback()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function shallowRender(component, context = {}) {
|
export function shallowRender(component, context = {}) {
|
||||||
const shallowRenderer = React.addons.TestUtils.createRenderer()
|
const shallowRenderer = React.addons.TestUtils.createRenderer()
|
||||||
shallowRenderer.render(component, context)
|
shallowRenderer.render(component, context)
|
||||||
return shallowRenderer.getRenderOutput()
|
return shallowRenderer.getRenderOutput()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function testIfDocumentFocused(message, fn) {
|
||||||
|
if (document.hasFocus && document.hasFocus()) {
|
||||||
|
test(message, fn)
|
||||||
|
} else {
|
||||||
|
test.skip(`${message} – WARNING: document is not focused`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,5 @@
|
|||||||
*
|
*
|
||||||
* See: https://github.com/webpack/docs/wiki/context
|
* See: https://github.com/webpack/docs/wiki/context
|
||||||
*/
|
*/
|
||||||
const specContext = require.context('.', true, /.+\.spec\.jsx?$/)
|
var context = require.context('.', true, /-test\.js$/)
|
||||||
specContext.keys().forEach(specContext)
|
context.keys().forEach(context)
|
||||||
module.exports = specContext
|
|
||||||
Reference in New Issue
Block a user