Skip to content

Commit 3c28a32

Browse files
author
connorwalsh
committed
update karma tests to create one test bundle, add more test coverage
1 parent 09eaf01 commit 3c28a32

36 files changed

Lines changed: 851 additions & 194 deletions

File tree

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"react",
55
"es2017",
66
"stage-0",
7-
"stage-1"
7+
"stage-1",
8+
"flow"
89
],
910
"plugins": [
1011
"transform-class-properties",

.flowconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[ignore]
2+
./node_modules
3+
4+
[include]
5+
./src
6+
./test
7+
8+
[libs]
9+
10+
[lints]
11+
12+
[options]

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ before_install:
44
- export DISPLAY=:99.0
55
- sh -e /etc/init.d/xvfb start
66
after_script:
7-
- npm run coverage
87
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js

karma.conf.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ module.exports = function(config) {
99
var configuration = {
1010
port: 9876,
1111
basePath: '.',
12+
// NOTE (cw|11.2.2017) we are bundling all tests into a single bundle because
13+
// for some reason, importing ToneJS within each test breaks stuff when we are
14+
// importing it more than 7 times (???). This must have something to do with using
15+
// the WebAudio API and instantiating it too many times or something.
16+
// The consequence is that there is no straightforward way to run individual tests
17+
// other than overwrit
1218
files: [
13-
{pattern: testPath + '**/*.js', included: true},
19+
'test/index.js',
20+
// {pattern: testPath + '**/*.js', included: true},
1421
],
1522
preprocessors: {
16-
[testPath + '**/*.js']: ['webpack'],
23+
'test/index.js': ['webpack', 'sourcemap'],
24+
// [testPath + '**/*.js']: ['webpack', 'sourcemap'],
1725
},
1826
webpack: webpackConfig,
1927
webpackServer: {
@@ -32,6 +40,7 @@ module.exports = function(config) {
3240
plugins: [
3341
'karma-webpack',
3442
'karma-coverage',
43+
'karma-sourcemap-loader',
3544
'karma-mocha',
3645
'karma-mocha-reporter',
3746
'karma-chai',

package-lock.json

Lines changed: 24 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"unitTests": "mocha-webpack test/unit --recursive",
88
"karmaTests": "./node_modules/karma/bin/karma start",
99
"lint": "eslint src",
10-
"test": "cross-env NODE_ENV=test npm run karmaTests",
11-
"coverage": ""
10+
"test": "npm run typeCheck && cross-env NODE_ENV=test npm run karmaTests",
11+
"typeCheck": "flow"
1212
},
1313
"repository": {
1414
"type": "git",
@@ -45,6 +45,7 @@
4545
"babel-plugin-transform-decorators-legacy": "^1.3.4",
4646
"babel-preset-es2015": "^6.0.15",
4747
"babel-preset-es2017": "^6.24.1",
48+
"babel-preset-flow": "^6.23.0",
4849
"babel-preset-latest": "^6.24.1",
4950
"babel-preset-react": "^6.0.15",
5051
"babel-preset-stage-0": "^6.0.15",
@@ -54,13 +55,15 @@
5455
"css-loader": "^0.23.1",
5556
"eslint": "^1.10.3",
5657
"eslint-plugin-react": "^3.6.2",
58+
"flow-bin": "^0.57.3",
5759
"istanbul": "^0.4.5",
5860
"karma": "^1.7.0",
5961
"karma-chai": "^0.1.0",
6062
"karma-chrome-launcher": "^2.1.1",
6163
"karma-coverage": "^1.1.1",
6264
"karma-mocha": "^1.3.0",
6365
"karma-mocha-reporter": "^2.2.3",
66+
"karma-sourcemap-loader": "^0.3.7",
6467
"karma-webpack": "^2.0.3",
6568
"mocha": "^3.4.1",
6669
"mocha-webpack": "^0.7.0",

src/components/editor/panels/timeline/midi/notes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {MidiNote} from './note'
88
import {
99
consolidateNotes,
1010
normalizeOverdubTime,
11-
} from '../../../../../redux/reducers/recordings/midi/midi'
11+
} from '../../../../../redux/reducers/recordings/midi/masters'
1212

1313

1414
export class MidiNotes extends Component {
@@ -177,7 +177,7 @@ export class MidiNotes extends Component {
177177

178178
transformInProgressRecordings() {
179179
const {inProgressRecordings} = this.props
180-
180+
181181
const transformedNotes = flatMap(
182182
values(inProgressRecordings),
183183
inProgressRecording => map(

src/middleware/midi/bus.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {fromMidi} from 'tonal-note'
55
import {play, playback} from '../../instruments/synth'
66
import {getMidiEventTypeAndChannel, MIDI_NOTE_OFF, MIDI_NOTE_ON} from '../../types/midiEvent'
77
import {recordMidiEvent} from '../../redux/actions/recordings/midi/midi'
8-
import {getUnmutedMasterRecordingsFromTimeline} from '../../redux/selectors/recordings/midi'
8+
import {getUnmutedMasterRecordingsFromTimeline} from '../../redux/selectors/timelines'
99

1010

1111
// Since the MidiAccess object cannot change object reference
@@ -202,9 +202,9 @@ export class MidiEventBus {
202202
}
203203

204204
record(deviceId, music) {
205-
const {recordingId, overdubId} = this.recording[deviceId]
205+
const {overdubId} = this.recording[deviceId]
206206

207-
this.dispatch(recordMidiEvent(recordingId, overdubId, music))
207+
this.dispatch(recordMidiEvent(overdubId, music))
208208
}
209209

210210
startPlayback(state, timelineId) {

src/redux/actions/recordings/midi/midi.js

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import uuidV4 from 'uuid/v4'
22
import {map} from 'lodash'
3-
import {newRecording} from '../../../../types/recording'
3+
import {newRecording, newOverdub} from '../../../../types/recording'
44
import {startPlayback, stopPlayback} from '../../timelines/timelines'
55

66

7-
87
export const MIDI_OVERDUB_RECORDING_STARTED = 'MIDI_OVERDUB_RECORDING_STARTED'
98
export const MIDI_OVERDUB_RECORDING_STOPPED = 'MIDI_OVERDUB_RECORDING_STOPPED'
109
export const MIDI_EVENT_RECORDED = 'MIDI_EVENT_RECORDED'
@@ -23,33 +22,15 @@ export const createNewMidiRecording = (recordingId = uuidV4()) => dispatch =>
2322
}
2423
})
2524

26-
/**
27-
* startMidiOverdub creates a new overdub recording within a given recording.
28-
*
29-
* @param deviceId: the id of the input midi device being recorded. This is not
30-
* stored in the redux store, but rather intercepted by the midi
31-
* middleware.
32-
* @param recordingId: the id of the recording for which this is an overdub.
33-
* @param overdubId (optional)
34-
*/
35-
// TODO (cw|2017.2017) get rid of this garbage, its not used anymore -____-
36-
export const startMidiOverdub = (deviceId, recordingId, overdubId = uuidV4(), timeOffset = 0) => dispatch => {
37-
dispatch({
38-
type: MIDI_OVERDUB_RECORDING_STARTED,
39-
payload: {
40-
input: deviceId,
41-
recordingId,
42-
overdub: newOverdub(overdubId, timeOffset)
43-
}
44-
})
45-
}
46-
47-
export const startMidiOverdubs = (recordings, timelineId) => dispatch => {
25+
export const startMidiOverdubs = (recordingContexts, timelineId) => dispatch => {
4826
// start overdub recording
4927
dispatch({
5028
type: MIDI_OVERDUB_RECORDING_STARTED,
5129
payload: {
52-
recordings: map(recordings, recording => ({...recording, overdubId: uuidV4()})),
30+
recordingContexts: map(
31+
recordingContexts,
32+
recordingContext => ({...recordingContext, overdub: newOverdub(uuidV4(), 0)}), // TODO (cw|10.29.2017) parameterize timeOffset
33+
),
5334
timelineId,
5435
},
5536
})
@@ -58,12 +39,12 @@ export const startMidiOverdubs = (recordings, timelineId) => dispatch => {
5839
dispatch(startPlayback(timelineId))
5940
}
6041

61-
export const stopMidiOverdubs = (recordings, timelineId) => dispatch => {
42+
export const stopMidiOverdubs = (recordingContexts, timelineId) => dispatch => {
6243
// stop overdub recording
6344
dispatch({
6445
type: MIDI_OVERDUB_RECORDING_STOPPED,
6546
payload: {
66-
recordings,
47+
recordingContexts,
6748
timelineId,
6849
},
6950
})
@@ -72,24 +53,6 @@ export const stopMidiOverdubs = (recordings, timelineId) => dispatch => {
7253
dispatch(stopPlayback(timelineId))
7354
}
7455

75-
/**
76-
* stopMidiOverdub stops recording an overdub.
77-
*
78-
* @param deviceId
79-
* @param recordingId
80-
* @param overdubId
81-
*/
82-
export const stopMidiOverdub = (deviceId, recordingId, overdubId) => dispatch => {
83-
dispatch({
84-
type: MIDI_OVERDUB_RECORDING_STOPPED,
85-
payload: {
86-
input: deviceId,
87-
recordingId,
88-
overdubId,
89-
}
90-
})
91-
}
92-
9356
/**
9457
* recordMidiEvent records a midi event to a recording overdub. This action should
9558
* only be used by the midi-middleware.
@@ -98,11 +61,10 @@ export const stopMidiOverdub = (deviceId, recordingId, overdubId) => dispatch =>
9861
* @param overdubId
9962
* @param midiEvent
10063
*/
101-
export const recordMidiEvent = (recordingId, overdubId, midiEvent) => dispatch => {
64+
export const recordMidiEvent = (overdubId, midiEvent) => dispatch => {
10265
dispatch({
10366
type: MIDI_EVENT_RECORDED,
10467
payload: {
105-
recordingId,
10668
overdubId,
10769
event: midiEvent,
10870
}

src/redux/reducers/recordings/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {combineReducers} from 'redux'
2-
import {midi} from './midi/midi'
2+
import {midi} from './midi'
33

44
export const recordings = combineReducers({
55
midi,

0 commit comments

Comments
 (0)