1
0
Fork 0

basic karma/mocha test suite setup

This commit is contained in:
lesion 2021-11-18 15:35:32 +01:00
parent af9f6c2598
commit 221430c017
5 changed files with 229 additions and 90 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
node_modules

34
karma.config.js Normal file
View file

@ -0,0 +1,34 @@
module.exports = function (config) {
config.set({
frameworks: ['mocha'],
// plugins: ['karma-webpack', 'karma-mocha', 'karma-chai-as-promised'],
webpack: {
// karma watches the test entry points
// Do NOT specify the entry option
// webpack watches dependencies
// webpack configuration
},
preprocessors: {
'test/**/*.js': ['webpack'],
'radiomanifest.js': ['webpack']
},
files: [
'radiomanifest.js',
'test/**/*.js'
],
reporters: ['progress'],
port: 9876, // karma web server port
colors: true,
logLevel: config.LOG_INFO,
browsers: ['ChromeHeadless', 'FirefoxHeadless'],
autoWatch: false,
concurrency: Infinity,
customLaunchers: {
FirefoxHeadless: {
base: 'Firefox',
flags: ['-headless'],
},
},
})
}

34
package.json Normal file
View file

@ -0,0 +1,34 @@
{
"name": "radiomanifest",
"version": "0.1.0",
"description": "",
"main": "radiomanifest.js",
"directories": {
"test": "tests"
},
"repository": {
"type": "git",
"url": "gogs@git.lattuga.net:lesion/radiomanifest.js.git"
},
"scripts": {
"test": "npm run test:node && npm run test:browser",
"test:node": "mocha",
"test:browser": "karma start --single-run --browsers ChromeHeadless,FirefoxHeadless karma.config.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"karma": "^6.3.9",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^2.1.2",
"karma-mocha": "^2.0.1",
"karma-webpack": "^5.0.0",
"mocha": "^9.1.3",
"webpack": "^5.64.1"
},
"dependencies": {
"isomorphic-unfetch": "^3.1.0"
}
}

View file

@ -1,3 +1,42 @@
const fetch = require('isomorphic-unfetch')
module.exports = {
/**
*
* @param {String} baseURL to search for a radiomanifest
*/
get (baseURL, options = { shows: false, streaming: false, calendar: false }) {
return new RadioManifest(baseURL, options )
}
}
class RadioManifest {
constructor (baseURL, options) {
this.baseURL = baseURL
this.options = options
const radiomanifest = fetch(`${baseURL}/radiomanifest.xml`)
return radiomanifest
}
getShowByName (showName) {
}
getStreaming () {
}
getSchedule () {
}
getShowAtTime () {
}
}
function getStreaminfoUrl(siteurl) {
return siteurl + '/streaminfo.json'; // XXX: improve this logic
}

View file

@ -0,0 +1,31 @@
const radiomanifest = require('../radiomanifest.js')
const chai = require('chai')
chai.use(require('chai-as-promised'))
const expect = chai.expect
describe('radiomanifest.js', () => {
describe('Get a radiomanifest', () => {
it('should return a Promise', () => {
const p = radiomanifest.get('http://omstring')
expect(p instanceof Promise).to.be.eql(true)
})
it('should reject on invalid URL', () => {
const p = radiomanifest.get('http://invalidurl')
expect(p).to.eventually.be.rejected
})
})
describe('streaming', () => {
it('shoud return a valid streaming URL', () => {
})
})
})