Skip to content

Commit

Permalink
Add basic karma testing
Browse files Browse the repository at this point in the history
Closes #22
For some reason the players do not work in Firefox on Travis, and I don't know why
See https://travis-ci.org/CookPete/react-player/jobs/100382039 for a travis log with SoundCloud debug logs
It seems to load the track correctly and run play(), but the stateChange event never happens (and so onPlay is never fired)
  • Loading branch information
cookpete committed Jan 7, 2016
1 parent 4517cc6 commit 447cf60
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ node_js:
- "iojs"
script:
- npm run lint
- npm run test
- npm run test:mocha
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"build:compile": "NODE_ENV=production babel src -d lib --ignore App.js,index.js",
"start": "node server.js",
"lint": "standard --verbose | snazzy",
"test:mocha": "NODE_ENV=production mocha --require ignore-styles test/mocha --compilers js:babel-core/register",
"test:karma": "karma start test/karma.config.js",
"test": "npm run test:mocha && npm run test:karma",
"preversion": "npm run lint && npm run test",
"version": "auto-changelog --package --template compact; git add CHANGELOG.md",
"prepublish": "npm run build:compile",
Expand Down Expand Up @@ -55,6 +58,15 @@
"extract-text-webpack-plugin": "^0.9.1",
"ignore-styles": "^1.1.0",
"imports-loader": "^0.6.4",
"karma": "^0.13.16",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^0.2.2",
"karma-cli": "^0.1.2",
"karma-firefox-launcher": "^0.1.7",
"karma-mocha": "^0.2.1",
"karma-mocha-reporter": "^1.1.5",
"karma-sourcemap-loader": "^0.3.6",
"karma-webpack": "^1.7.0",
"mocha": "^2.3.4",
"node-sass": "^3.4.2",
"react": "^0.14.0",
Expand Down
26 changes: 26 additions & 0 deletions test/karma.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var webpackConfig = require('../webpack.config.dev')
webpackConfig.devtool = 'inline-source-map'

module.exports = function (config) {
config.set({
browsers: process.env.CONTINUOUS_INTEGRATION ? [ 'Firefox' ] : [ 'Chrome', 'Firefox' ],
singleRun: true,
frameworks: [ 'mocha', 'chai' ],
files: [
'karma.webpack.js'
],
preprocessors: {
'karma.webpack.js': [ 'webpack', 'sourcemap' ]
},
reporters: [ 'mocha' ],
webpack: webpackConfig,
webpackServer: {
noInfo: true
},
client: {
mocha: {
timeout: 10000
}
}
})
}
2 changes: 2 additions & 0 deletions test/karma.webpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var context = require.context('./karma', true, /\.js$/)
context.keys().forEach(context)
44 changes: 44 additions & 0 deletions test/karma/ReactPlayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react'
import { render, unmountComponentAtNode } from 'react-dom'

import ReactPlayer from '../../src/ReactPlayer'

const { describe, it, beforeEach, afterEach } = window
const TEST_YOUTUBE_URL = 'https://www.youtube.com/watch?v=GlCmAC4MHek'
const TEST_SOUNDCLOUD_URL = 'https://soundcloud.com/miami-nights-1984/accelerated'
const TEST_VIMEO_URL = 'https://vimeo.com/90509568'
const TEST_MP4_URL = 'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'

describe('ReactPlayer', () => {
let div

beforeEach(() => {
div = document.createElement('div')
document.body.appendChild(div)
})

it('plays a YouTube video', function (done) {
const player = <ReactPlayer url={TEST_YOUTUBE_URL} playing onPlay={() => done()} />
render(player, div)
})

it('plays a SoundCloud track', function (done) {
const player = <ReactPlayer url={TEST_SOUNDCLOUD_URL} playing onPlay={() => done()} />
render(player, div)
})

it('plays a Vimeo video', function (done) {
const player = <ReactPlayer url={TEST_VIMEO_URL} playing onPlay={() => done()} />
render(player, div)
})

it('plays an mp4', function (done) {
const player = <ReactPlayer url={TEST_MP4_URL} playing onPlay={() => done()} />
render(player, div)
})

afterEach(() => {
unmountComponentAtNode(div)
document.body.removeChild(div)
})
})
10 changes: 5 additions & 5 deletions test/ReactPlayer.js → test/mocha/ReactPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { describe, it, beforeEach } from 'mocha'
import { expect } from 'chai'
import { createRenderer } from 'react-addons-test-utils'

import ReactPlayer from '../src/ReactPlayer'
import YouTube from '../src/players/YouTube'
import Vimeo from '../src/players/Vimeo'
import SoundCloud from '../src/players/SoundCloud'
import FilePlayer from '../src/players/FilePlayer'
import ReactPlayer from '../../src/ReactPlayer'
import YouTube from '../../src/players/YouTube'
import Vimeo from '../../src/players/Vimeo'
import SoundCloud from '../../src/players/SoundCloud'
import FilePlayer from '../../src/players/FilePlayer'

const YOUTUBE_URL = 'https://www.youtube.com/watch?v=oUFJJNQGwhk'
const SOUNDCLOUD_URL = 'https://soundcloud.com/miami-nights-1984/accelerated'
Expand Down
8 changes: 4 additions & 4 deletions test/canPlay.js → test/mocha/canPlay.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describe, it } from 'mocha'
import { expect } from 'chai'

import SoundCloud from '../src/players/SoundCloud'
import YouTube from '../src/players/YouTube'
import Vimeo from '../src/players/Vimeo'
import FilePlayer from '../src/players/FilePlayer'
import SoundCloud from '../../src/players/SoundCloud'
import YouTube from '../../src/players/YouTube'
import Vimeo from '../../src/players/Vimeo'
import FilePlayer from '../../src/players/FilePlayer'

describe('YouTube', () => {
it('knows what it can play', () => {
Expand Down

0 comments on commit 447cf60

Please sign in to comment.