Skip to content

Commit

Permalink
test: move tests around (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Jan 21, 2021
1 parent 985ab68 commit e86dcae
Show file tree
Hide file tree
Showing 124 changed files with 521 additions and 772 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"ignore": [
"dist",
"docs",
"test/dist"
"test/dist",
"test/fixtures"
]
},
"files": [
Expand Down
6 changes: 3 additions & 3 deletions scripts/export-m3u8s.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path');

const basePath = path.resolve(__dirname, '..');
const testDataDir = path.join(basePath, 'test');
const manifestDir = path.join(basePath, 'test', 'fixtures', 'm3u8');
const manifestDir = path.join(basePath, 'test', 'fixtures', 'integration');
const manifestFilepath = path.join(testDataDir, 'dist', 'test-manifests.js');
const expectedFilepath = path.join(testDataDir, 'dist', 'test-expected.js');

Expand All @@ -32,9 +32,9 @@ const build = function() {
// strip leading spaces and the trailing '+'
.slice(4, -3);
manifests += ',\n';
} else if (extname === '.json') {
} else if (extname === '.js') {
// append the expected parse
expected += ' "' + path.basename(file, '.json') + '": ';
expected += ' "' + path.basename(file, '.js') + '": ';
expected += fs.readFileSync(file, 'utf8');
expected += ',\n';
} else {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions test/fixtures/m3u8/media1.m3u8

This file was deleted.

13 changes: 0 additions & 13 deletions test/fixtures/m3u8/media2.m3u8

This file was deleted.

13 changes: 0 additions & 13 deletions test/fixtures/m3u8/media3.m3u8

This file was deleted.

58 changes: 0 additions & 58 deletions test/fixtures/m3u8/playlist_allow_cache_template.m3u8

This file was deleted.

60 changes: 0 additions & 60 deletions test/fixtures/m3u8/playlist_byte_range_template.m3u8

This file was deleted.

57 changes: 0 additions & 57 deletions test/fixtures/m3u8/playlist_extinf_template.m3u8

This file was deleted.

15 changes: 0 additions & 15 deletions test/fixtures/m3u8/playlist_media_sequence_template.m3u8

This file was deleted.

14 changes: 0 additions & 14 deletions test/fixtures/m3u8/playlist_target_duration_template.m3u8

This file was deleted.

17 changes: 0 additions & 17 deletions test/fixtures/m3u8/playlist_type_template.m3u8

This file was deleted.

80 changes: 80 additions & 0 deletions test/line-stream.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {LineStream} from '../src';
import QUnit from 'qunit';

QUnit.module('LineStream', {
beforeEach() {
this.lineStream = new LineStream();
}
});
QUnit.test('empty inputs produce no tokens', function(assert) {
let data = false;

this.lineStream.on('data', function() {
data = true;
});
this.lineStream.push('');
assert.ok(!data, 'no tokens were produced');
});
QUnit.test('splits on newlines', function(assert) {
const lines = [];

this.lineStream.on('data', function(line) {
lines.push(line);
});
this.lineStream.push('#EXTM3U\nmovie.ts\n');

assert.strictEqual(2, lines.length, 'two lines are ready');
assert.strictEqual('#EXTM3U', lines.shift(), 'the first line is the first token');
assert.strictEqual('movie.ts', lines.shift(), 'the second line is the second token');
});
QUnit.test('empty lines become empty strings', function(assert) {
const lines = [];

this.lineStream.on('data', function(line) {
lines.push(line);
});
this.lineStream.push('\n\n');

assert.strictEqual(2, lines.length, 'two lines are ready');
assert.strictEqual('', lines.shift(), 'the first line is empty');
assert.strictEqual('', lines.shift(), 'the second line is empty');
});
QUnit.test('handles lines broken across appends', function(assert) {
const lines = [];

this.lineStream.on('data', function(line) {
lines.push(line);
});
this.lineStream.push('#EXTM');
assert.strictEqual(0, lines.length, 'no lines are ready');

this.lineStream.push('3U\nmovie.ts\n');
assert.strictEqual(2, lines.length, 'two lines are ready');
assert.strictEqual('#EXTM3U', lines.shift(), 'the first line is the first token');
assert.strictEqual('movie.ts', lines.shift(), 'the second line is the second token');
});
QUnit.test('stops sending events after deregistering', function(assert) {
const temporaryLines = [];
const temporary = function(line) {
temporaryLines.push(line);
};
const permanentLines = [];
const permanent = function(line) {
permanentLines.push(line);
};

this.lineStream.on('data', temporary);
this.lineStream.on('data', permanent);
this.lineStream.push('line one\n');
assert.strictEqual(
temporaryLines.length,
permanentLines.length,
'both callbacks receive the event'
);

assert.ok(this.lineStream.off('data', temporary), 'a listener was removed');
this.lineStream.push('line two\n');
assert.strictEqual(1, temporaryLines.length, 'no new events are received');
assert.strictEqual(2, permanentLines.length, 'new events are still received');
});

Loading

0 comments on commit e86dcae

Please sign in to comment.