@internetarchive/radio-player 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/.eslintrc +0 -37
- package/.gitignore +0 -11
- package/.storybook/.babelrc +0 -15
- package/.storybook/addons.js +0 -7
- package/.storybook/config.js +0 -11
- package/.storybook/webpack.config.js +0 -5
- package/demo/full-text-search-service.ts +0 -32
- package/demo/index.html +0 -53
- package/demo/radio-player-controller.ts +0 -237
- package/karma.bs.config.js +0 -16
- package/karma.conf.js +0 -66
- package/package-lock.json +0 -51719
- package/stories/index.stories.js +0 -40
- package/stories/transcript.js +0 -683
- package/test/assets/arrow.mp3 +0 -0
- package/test/music-zone.test.js +0 -13
- package/test/promised-sleep.js +0 -3
- package/test/radio-player-config.test.js +0 -42
- package/test/radio-player.test.js +0 -1072
- package/test/sample_transcript.js +0 -1493
- package/test/search-handler/search-backends/full-text-sample-response-brackets.js +0 -60
- package/test/search-handler/search-backends/full-text-sample-response-em.js +0 -60
- package/test/search-handler/search-backends/full-text-search-backend.test.js +0 -74
- package/test/search-handler/search-backends/full-text-search-response.test.js +0 -14
- package/test/search-handler/search-backends/local-search-backend.test.js +0 -39
- package/test/search-handler/search-handler.test.js +0 -550
- package/test/search-handler/search-helper.test.js +0 -63
- package/test/search-handler/search-model.test.js +0 -56
- package/test/search-handler/transcript-index.test.js +0 -66
- package/test/search-results-switcher.test.js +0 -97
- package/tsconfig.build.json +0 -7
- package/tsconfig.json +0 -21
- package/yarn.lock +0 -14450
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internetarchive/radio-player",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "A Radio Player LitElement.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"main": "index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@internetarchive/audio-element": "^0.0.2",
|
|
38
38
|
"@internetarchive/expandable-search-bar": "^0.0.2",
|
|
39
|
-
"@internetarchive/ia-activity-indicator": "^0.0.
|
|
39
|
+
"@internetarchive/ia-activity-indicator": "^0.0.4",
|
|
40
40
|
"@internetarchive/playback-controls": "0.0.2",
|
|
41
41
|
"@internetarchive/scrubber-bar": "^0.0.2",
|
|
42
42
|
"@internetarchive/transcript-view": "^0.0.3",
|
package/.eslintrc
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"parser": "@typescript-eslint/parser",
|
|
3
|
-
"plugins": ["@typescript-eslint"],
|
|
4
|
-
"extends": [
|
|
5
|
-
"plugin:@typescript-eslint/recommended",
|
|
6
|
-
"@open-wc",
|
|
7
|
-
"prettier"
|
|
8
|
-
],
|
|
9
|
-
"rules": {
|
|
10
|
-
"no-unused-vars": "off",
|
|
11
|
-
"max-classes-per-file": "off",
|
|
12
|
-
"@typescript-eslint/no-unused-vars": [
|
|
13
|
-
"error"
|
|
14
|
-
],
|
|
15
|
-
"no-shadow": "off",
|
|
16
|
-
"@typescript-eslint/no-shadow": [
|
|
17
|
-
"error"
|
|
18
|
-
],
|
|
19
|
-
"class-methods-use-this": "off",
|
|
20
|
-
"import/no-unresolved": "off",
|
|
21
|
-
"import/extensions": [
|
|
22
|
-
"off",
|
|
23
|
-
"ignorePackages",
|
|
24
|
-
{
|
|
25
|
-
"js": "never",
|
|
26
|
-
"ts": "never"
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
},
|
|
30
|
-
"settings": {
|
|
31
|
-
"import/resolver": {
|
|
32
|
-
"node": {
|
|
33
|
-
"extensions": [".js", ".jsx", ".ts", ".tsx"]
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
package/.gitignore
DELETED
package/.storybook/.babelrc
DELETED
package/.storybook/addons.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import '@storybook/addon-a11y/register';
|
|
2
|
-
import '@storybook/addon-actions/register';
|
|
3
|
-
import '@storybook/addon-knobs/register';
|
|
4
|
-
import '@storybook/addon-notes/register';
|
|
5
|
-
import '@storybook/addon-links/register';
|
|
6
|
-
import '@storybook/addon-storysource/register';
|
|
7
|
-
import '@storybook/addon-viewport/register';
|
package/.storybook/config.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { configure, addDecorator } from '@storybook/polymer';
|
|
2
|
-
import { withA11y } from '@storybook/addon-a11y';
|
|
3
|
-
import '@storybook/addon-console';
|
|
4
|
-
|
|
5
|
-
const req = require.context('../stories', true, /\.stories\.js$/);
|
|
6
|
-
function loadStories() {
|
|
7
|
-
req.keys().forEach(filename => req(filename));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
addDecorator(withA11y);
|
|
11
|
-
configure(loadStories, module);
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { FullTextSearchServiceInterface } from '../src/search-handler/search-backends/full-text-search-backend/full-text-search-service-interface';
|
|
2
|
-
import { FullTextSearchResponse } from '../src/search-handler/search-backends/full-text-search-backend/full-text-search-response';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* An example FullTextSearchService that fetches data from the backend and
|
|
6
|
-
* returns a Promise<FullTextSearch> response.
|
|
7
|
-
*/
|
|
8
|
-
export class FullTextSearchService implements FullTextSearchServiceInterface {
|
|
9
|
-
private itemId: string;
|
|
10
|
-
|
|
11
|
-
private baseUrl: string;
|
|
12
|
-
|
|
13
|
-
private searchServicePath: string;
|
|
14
|
-
|
|
15
|
-
constructor(itemId: string, baseUrl: string, searchServicePath: string) {
|
|
16
|
-
this.itemId = itemId;
|
|
17
|
-
this.baseUrl = baseUrl;
|
|
18
|
-
this.searchServicePath = searchServicePath;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** @inheritdoc */
|
|
22
|
-
async searchRequested(query: string): Promise<FullTextSearchResponse> {
|
|
23
|
-
const searchUrl = `${this.baseUrl}${this.searchServicePath}`;
|
|
24
|
-
const queryParams = `?q=${query}&identifier=${this.itemId}&number_of_fragments=1000&scope=all`;
|
|
25
|
-
const url = `${searchUrl}${queryParams}`;
|
|
26
|
-
const rawResponse = await fetch(url);
|
|
27
|
-
const jsonResponse = await rawResponse.json();
|
|
28
|
-
const modeledResponse = new FullTextSearchResponse(jsonResponse);
|
|
29
|
-
|
|
30
|
-
return new Promise(resolve => resolve(modeledResponse));
|
|
31
|
-
}
|
|
32
|
-
}
|
package/demo/index.html
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
|
|
7
|
-
<style>
|
|
8
|
-
body {
|
|
9
|
-
background: #000;
|
|
10
|
-
font-family: sans-serif;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
radio-player-controller {
|
|
14
|
-
display: block;
|
|
15
|
-
border-bottom: 1px solid white;
|
|
16
|
-
line-height: 1.5rem;
|
|
17
|
-
color: white;
|
|
18
|
-
|
|
19
|
-
--timeColor: white;
|
|
20
|
-
--timeColumnWidth: 3rem;
|
|
21
|
-
--transcriptHeight: 400px;
|
|
22
|
-
|
|
23
|
-
--autoScrollButtonFontColor: black;
|
|
24
|
-
--autoScrollButtonBackgroundColor: white;
|
|
25
|
-
|
|
26
|
-
--normalTextColor: gray;
|
|
27
|
-
--activeTextColor: white;
|
|
28
|
-
--searchResultInactiveBorderColor: gray;
|
|
29
|
-
--searchResultActiveBorderColor: green;
|
|
30
|
-
|
|
31
|
-
--trackColor: black;
|
|
32
|
-
--trackBorder: 1px solid white;
|
|
33
|
-
}
|
|
34
|
-
</style>
|
|
35
|
-
</head>
|
|
36
|
-
<body>
|
|
37
|
-
<div id="demo">
|
|
38
|
-
</div>
|
|
39
|
-
|
|
40
|
-
<script type="module">
|
|
41
|
-
import { html, render } from 'lit';
|
|
42
|
-
import '../lib/demo/radio-player-controller.js';
|
|
43
|
-
|
|
44
|
-
render(
|
|
45
|
-
html`
|
|
46
|
-
<radio-player-controller>
|
|
47
|
-
</radio-player-controller>
|
|
48
|
-
`,
|
|
49
|
-
document.querySelector('#demo')
|
|
50
|
-
);
|
|
51
|
-
</script>
|
|
52
|
-
</body>
|
|
53
|
-
</html>
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-duplicates */
|
|
2
|
-
import {
|
|
3
|
-
LitElement,
|
|
4
|
-
html,
|
|
5
|
-
TemplateResult,
|
|
6
|
-
PropertyValues,
|
|
7
|
-
} from 'lit';
|
|
8
|
-
import {
|
|
9
|
-
customElement,
|
|
10
|
-
property,
|
|
11
|
-
} from 'lit/decorators.js';
|
|
12
|
-
|
|
13
|
-
import { AudioSource } from '@internetarchive/audio-element';
|
|
14
|
-
import { TranscriptConfig, TranscriptEntryConfig } from '@internetarchive/transcript-view';
|
|
15
|
-
|
|
16
|
-
import '../src/radio-player';
|
|
17
|
-
import RadioPlayer from '../src/radio-player';
|
|
18
|
-
import RadioPlayerConfig from '../src/models/radio-player-config';
|
|
19
|
-
import { SearchHandler } from '../src/search-handler/search-handler';
|
|
20
|
-
import { SearchHandlerInterface } from '../src/search-handler/search-handler-interface';
|
|
21
|
-
import { TranscriptIndex } from '../src/search-handler/transcript-index';
|
|
22
|
-
import { FullTextSearchBackend } from '../src/search-handler/search-backends/full-text-search-backend/full-text-search-backend';
|
|
23
|
-
import { SearchBackendInterface } from '../src/search-handler/search-backends/search-backend-interface';
|
|
24
|
-
import { FullTextSearchService } from './full-text-search-service';
|
|
25
|
-
import { FullTextSearchServiceInterface } from '../src/search-handler/search-backends/full-text-search-backend/full-text-search-service-interface';
|
|
26
|
-
// import { LocalSearchBackend } from '../src/search-handler/search-indices/local-search-index';
|
|
27
|
-
|
|
28
|
-
@customElement('radio-player-controller')
|
|
29
|
-
export default class RadioPlayerController extends LitElement {
|
|
30
|
-
@property({ type: Object }) radioPlayerConfig: RadioPlayerConfig | undefined = undefined;
|
|
31
|
-
|
|
32
|
-
@property({ type: Object }) transcriptConfig: TranscriptConfig | undefined = undefined;
|
|
33
|
-
|
|
34
|
-
@property({ type: String }) itemId: string | undefined = 'Euronews_Radio_English_20171029_030000';
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The Search Handler
|
|
38
|
-
*
|
|
39
|
-
* @type {(SearchHandlerInterface | undefined)}
|
|
40
|
-
* @memberof RadioPlayer
|
|
41
|
-
*/
|
|
42
|
-
@property({ type: Object }) searchHandler: SearchHandlerInterface | undefined = undefined;
|
|
43
|
-
|
|
44
|
-
private startPlaybackAt: number | undefined = undefined;
|
|
45
|
-
|
|
46
|
-
private currentTime = 0;
|
|
47
|
-
|
|
48
|
-
private fileName = '';
|
|
49
|
-
|
|
50
|
-
private baseUrl = 'https://archive.org';
|
|
51
|
-
|
|
52
|
-
private searchServicePath = '/services/radio-archive/search/service.php';
|
|
53
|
-
|
|
54
|
-
private searchBackend: SearchBackendInterface | undefined;
|
|
55
|
-
|
|
56
|
-
private searchService: FullTextSearchServiceInterface | undefined;
|
|
57
|
-
|
|
58
|
-
render(): TemplateResult {
|
|
59
|
-
return html`
|
|
60
|
-
<radio-player
|
|
61
|
-
.config=${this.radioPlayerConfig}
|
|
62
|
-
.transcriptConfig=${this.transcriptConfig}
|
|
63
|
-
.searchHandler=${this.searchHandler}
|
|
64
|
-
@searchTermChanged=${this.searchTermChanged}
|
|
65
|
-
@playbackPaused=${this.playbackPaused}
|
|
66
|
-
@currentTimeChanged=${this.currentTimeChanged}
|
|
67
|
-
@timeChangedFromScrub=${this.timeChangedFromScrub}
|
|
68
|
-
@transcriptEntrySelected=${this.transcriptEntrySelected}
|
|
69
|
-
@canplay=${this.canplay}
|
|
70
|
-
>
|
|
71
|
-
</radio-player>
|
|
72
|
-
`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
76
|
-
async loadItemMetadata(): Promise<any> {
|
|
77
|
-
const url = `https://archive.org/metadata/${this.itemId}`;
|
|
78
|
-
const response = await fetch(url);
|
|
79
|
-
const data = await response.json();
|
|
80
|
-
|
|
81
|
-
this.handleMetadataResponse(data);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async fetchTranscript(): Promise<any> {
|
|
85
|
-
const srtUrl = `https://archive.org/cors/${this.itemId}/${this.fileName}`;
|
|
86
|
-
|
|
87
|
-
const response = await fetch(srtUrl);
|
|
88
|
-
const json = await response.json();
|
|
89
|
-
|
|
90
|
-
const transcriptEntries = json.map(
|
|
91
|
-
(entry: any) => new TranscriptEntryConfig(
|
|
92
|
-
entry.id,
|
|
93
|
-
entry.start,
|
|
94
|
-
entry.end,
|
|
95
|
-
entry.text,
|
|
96
|
-
entry.is_music,
|
|
97
|
-
entry.search_match_index,
|
|
98
|
-
),
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
this.transcriptConfig = new TranscriptConfig(transcriptEntries);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async setup(): Promise<any> {
|
|
105
|
-
await this.loadItemMetadata();
|
|
106
|
-
await this.fetchTranscript();
|
|
107
|
-
|
|
108
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
109
|
-
const searchTerm = searchParams.get('q');
|
|
110
|
-
const startTime = searchParams.get('start');
|
|
111
|
-
|
|
112
|
-
if (searchTerm && this.radioPlayer) {
|
|
113
|
-
this.radioPlayer.searchTerm = searchTerm;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (startTime) {
|
|
117
|
-
this.startPlaybackAt = parseFloat(startTime);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
handleMetadataResponse(response: any): void {
|
|
122
|
-
const metadata = response;
|
|
123
|
-
const collectionIdentifier = metadata.metadata.collection[0];
|
|
124
|
-
const srtFile = metadata.files.find((file: any) => file.format === 'JSON SRT');
|
|
125
|
-
this.fileName = srtFile.name;
|
|
126
|
-
|
|
127
|
-
const originalAudioFile = metadata.files.find(
|
|
128
|
-
(file: any) => file.source === 'original'
|
|
129
|
-
&& ['vbr mp3', 'ogg vorbis', 'advanced audio coding'].includes(file.format.toLowerCase()),
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
const audioFiles = metadata.files.filter((file: any) => [
|
|
133
|
-
'vbr mp3', 'ogg vorbis'].includes(file.format.toLowerCase()),);
|
|
134
|
-
|
|
135
|
-
const audioSources = audioFiles.map((file: any) => {
|
|
136
|
-
const url = `https://archive.org/download/${this.itemId}/${file.name}`;
|
|
137
|
-
const mimetype = file.format.toLowerCase() === 'ogg vorbis' ? 'audio/ogg' : 'audio/mpeg';
|
|
138
|
-
return new AudioSource(url, mimetype);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
const waveFormImageFile = metadata.files.find(
|
|
142
|
-
(file: any) => file.format.toLowerCase() === 'png'
|
|
143
|
-
&& file.original === originalAudioFile.name,
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
let waveFormImageUrl;
|
|
147
|
-
|
|
148
|
-
if (waveFormImageFile) {
|
|
149
|
-
waveFormImageUrl = `https://archive.org/download/${this.itemId}/${waveFormImageFile.name}`;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
this.radioPlayerConfig = new RadioPlayerConfig(
|
|
153
|
-
metadata.metadata.contributor,
|
|
154
|
-
metadata.metadata.start_localtime || metadata.metadata.start_time,
|
|
155
|
-
`https://archive.org/services/img/${collectionIdentifier}`,
|
|
156
|
-
waveFormImageUrl,
|
|
157
|
-
audioSources,
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
161
|
-
|
|
162
|
-
private get radioPlayer(): RadioPlayer | null {
|
|
163
|
-
return this.shadowRoot ? (this.shadowRoot.querySelector('radio-player') as RadioPlayer) : null;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
firstUpdated(): void {
|
|
167
|
-
this.setup();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
updated(changedProperties: PropertyValues): void {
|
|
171
|
-
if (changedProperties.has('transcriptConfig')) {
|
|
172
|
-
this.setupSearchHandler();
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
private setupSearchHandler(): void {
|
|
177
|
-
if (!this.transcriptConfig || !this.itemId) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
const transcriptIndex = new TranscriptIndex(this.transcriptConfig);
|
|
181
|
-
// const searchBackend = new LocalSearchBackend();
|
|
182
|
-
this.searchService = new FullTextSearchService(
|
|
183
|
-
this.itemId, this.baseUrl, this.searchServicePath
|
|
184
|
-
);
|
|
185
|
-
const searchBackend = new FullTextSearchBackend(this.searchService);
|
|
186
|
-
this.searchBackend = searchBackend;
|
|
187
|
-
const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
|
|
188
|
-
this.searchHandler = searchHandler;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private canplay(): void {
|
|
192
|
-
if (this.startPlaybackAt && this.radioPlayer) {
|
|
193
|
-
this.radioPlayer.seekTo(this.startPlaybackAt);
|
|
194
|
-
this.startPlaybackAt = undefined;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private searchTermChanged(e: CustomEvent): void {
|
|
199
|
-
const { searchTerm } = e.detail;
|
|
200
|
-
this.updateSearchQueryParam(searchTerm);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
private currentTimeChanged(e: CustomEvent): void {
|
|
204
|
-
this.currentTime = e.detail.currentTime;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
private playbackPaused(): void {
|
|
208
|
-
this.updateStartTimeQueryParam();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
private timeChangedFromScrub(e: CustomEvent): void {
|
|
212
|
-
this.currentTime = e.detail.newTime;
|
|
213
|
-
this.updateStartTimeQueryParam();
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
private transcriptEntrySelected(e: CustomEvent): void {
|
|
217
|
-
this.currentTime = e.detail.newTime;
|
|
218
|
-
this.updateStartTimeQueryParam();
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
private updateStartTimeQueryParam(): void {
|
|
222
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
223
|
-
searchParams.set('start', `${this.currentTime}`);
|
|
224
|
-
window.history.replaceState({}, '', `?${searchParams.toString()}`);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/* eslint-disable-next-line class-methods-use-this */
|
|
228
|
-
private updateSearchQueryParam(searchTerm: string): void {
|
|
229
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
230
|
-
if (searchTerm === '') {
|
|
231
|
-
searchParams.delete('q');
|
|
232
|
-
} else {
|
|
233
|
-
searchParams.set('q', `${searchTerm}`);
|
|
234
|
-
}
|
|
235
|
-
window.history.replaceState({}, '', `?${searchParams.toString()}`);
|
|
236
|
-
}
|
|
237
|
-
}
|
package/karma.bs.config.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
-
const merge = require('deepmerge');
|
|
3
|
-
const bsSettings = require('@open-wc/testing-karma-bs/bs-settings.js');
|
|
4
|
-
const createBaseConfig = require('./karma.conf.js');
|
|
5
|
-
|
|
6
|
-
module.exports = (config) => {
|
|
7
|
-
config.set(
|
|
8
|
-
merge(bsSettings(config), createBaseConfig(config), {
|
|
9
|
-
browserStack: {
|
|
10
|
-
project: 'radio-player',
|
|
11
|
-
},
|
|
12
|
-
}),
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
return config;
|
|
16
|
-
};
|
package/karma.conf.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
-
const { createDefaultConfig } = require('@open-wc/testing-karma');
|
|
3
|
-
const merge = require('deepmerge');
|
|
4
|
-
|
|
5
|
-
module.exports = (config) => {
|
|
6
|
-
config.set(
|
|
7
|
-
merge(createDefaultConfig(config), {
|
|
8
|
-
files: [
|
|
9
|
-
// runs all files ending with .test in the test folder,
|
|
10
|
-
// can be overwritten by passing a --grep flag. examples:
|
|
11
|
-
//
|
|
12
|
-
// npm run test -- --grep test/foo/bar.test.js
|
|
13
|
-
// npm run test -- --grep test/bar/*
|
|
14
|
-
{
|
|
15
|
-
pattern: 'test/**/*.mp3', watched: false, included: false, served: true
|
|
16
|
-
},
|
|
17
|
-
{ pattern: config.grep ? config.grep : 'test/**/*.test.js', type: 'module' },
|
|
18
|
-
],
|
|
19
|
-
|
|
20
|
-
customLaunchers: {
|
|
21
|
-
ChromeHeadlessAutoplayAllowed: {
|
|
22
|
-
base: 'ChromeHeadless',
|
|
23
|
-
flags: [
|
|
24
|
-
// needed to test playback via javascript since the browser
|
|
25
|
-
// doesn't allow automated playback without user interaction
|
|
26
|
-
'--autoplay-policy=no-user-gesture-required',
|
|
27
|
-
'--no-sandbox',
|
|
28
|
-
'--disable-setuid-sandbox'
|
|
29
|
-
],
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
esm: {
|
|
34
|
-
preserveSymlinks: true,
|
|
35
|
-
nodeResolve: true
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
proxies: {
|
|
39
|
-
'/assets/': '/base/test/assets/'
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
reporters: [
|
|
43
|
-
// Reference: https://github.com/karma-runner/karma-coverage
|
|
44
|
-
// Output code coverage files
|
|
45
|
-
'coverage'
|
|
46
|
-
],
|
|
47
|
-
|
|
48
|
-
// Configure code coverage reporter
|
|
49
|
-
coverageReporter: {
|
|
50
|
-
reporters: [
|
|
51
|
-
// generates ./coverage/lcov.info
|
|
52
|
-
{ type: 'lcovonly', subdir: '.' },
|
|
53
|
-
// generates ./coverage/coverage-final.json
|
|
54
|
-
{ type: 'json', subdir: '.' },
|
|
55
|
-
]
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
plugins: [
|
|
59
|
-
require.resolve('@open-wc/karma-esm'),
|
|
60
|
-
'karma-coverage'
|
|
61
|
-
],
|
|
62
|
-
}),
|
|
63
|
-
);
|
|
64
|
-
config.browsers = ['ChromeHeadlessAutoplayAllowed'];
|
|
65
|
-
return config;
|
|
66
|
-
};
|