From bcfbada46c78a1318f63086571f1461951ece01d Mon Sep 17 00:00:00 2001 From: Trivernis Date: Tue, 22 Jan 2019 21:21:53 +0100 Subject: [PATCH] TestScripts 1 - added circleci configuration - added mockobjects for testing without the discord api - added a testscript for the music library --- .circleci/config.yml | 41 ++++++++++++++++++++++++++++++++++++++ package.json | 3 +++ testscripts/mockobjects.js | 38 +++++++++++++++++++++++++++++++++++ testscripts/musicTest.js | 32 +++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 .circleci/config.yml create mode 100644 testscripts/mockobjects.js create mode 100644 testscripts/musicTest.js diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..79e9b34 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,41 @@ +# Javascript Node CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-javascript/ for more details +# +version: 2 +jobs: + build: + docker: + # specify the version you desire here + - image: circleci/node:7.10 + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # - image: circleci/mongo:3.4.4 + + working_directory: ~/repo + + steps: + - checkout + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "package.json" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: + name: Installing dependencies + command: npm install + + - save_cache: + paths: + - node_modules + key: v1-dependencies-{{ checksum "package.json" }} + + # run tests! + - run: + name: Testing ./lib/music + command: node ./test/musicTest.js \ No newline at end of file diff --git a/package.json b/package.json index 3b16f26..f6b6d9a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,9 @@ { "name": "discordbot", "version": "1.0.0", + "scripts": { + "start": "node bot.js" + }, "dependencies": { "args-parser": "1.1.0", "discord.js": "11.4.2", diff --git a/testscripts/mockobjects.js b/testscripts/mockobjects.js new file mode 100644 index 0000000..db66e94 --- /dev/null +++ b/testscripts/mockobjects.js @@ -0,0 +1,38 @@ +exports.mockDispatcher = { + pause: () => console.log('pause();'), + resume: () => console.log('resume();'), + setVolume: (perc) => console.log(`setVolume(${perc});`), + on: (event, callback) => console.log(`on(${event}, ${callback});`), + end: () => console.log('end();') +}; + +exports.mockConnection = { + channel: { + members: { + size: 10 + }, + leave: () => console.log('leave();') + }, + status: 0, + playFile: (fname) => { + console.log(`playFile(${fname});`); + return exports.mockDispatcher; + }, + playStream: (stream, opts) => { + console.log(`playStream(ytdl, ${opts};`); + return exports.mockDispatcher; + }, + disconnect: () => console.log('disconnect();') +}; + +exports.mockVoicechannel = { + name: 'mockVoicechannel', + join: () => { + console.log('join();'); + return new Promise((rs, rj) => rs(exports.mockConnection)); + }, + members: { + size: 10 + }, + leave: () => console.log('leave();') +}; \ No newline at end of file diff --git a/testscripts/musicTest.js b/testscripts/musicTest.js new file mode 100644 index 0000000..917ecec --- /dev/null +++ b/testscripts/musicTest.js @@ -0,0 +1,32 @@ +const music = require('../lib/music.js'), + mockclasses = require('./mockobjects.js'); + +function main() { + let dj = new music.DJ(mockclasses.mockVoicechannel) + music.setLogger({ + error: () => {}, + warn: () => {}, + info: () => {}, + verbose: () => {}, + debug: () => {} + }); + dj.connect().then(() => { + console.log('connected', dj.connected); + dj.playFile('test'); + dj.playYouTube('https://www.youtube.com/watch?v=TEST'); + dj.setVolume(1); + dj.pause(); + dj.resume(); + dj.skip(); + dj.stop(); + dj.shuffle(); + console.log(dj.playlist); + console.log(dj.song); + dj.clear(); + }); +} + +// Executing the main function +if (typeof require !== 'undefined' && require.main === module) { + main(); +} \ No newline at end of file