diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3781c8b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: node_js +node_js: + - "7" + - "6" +install: + - npm install +script: + - npm run test:server + - npm run cloc +after_success: npm run coverage \ No newline at end of file diff --git a/assets/scripts/api/local.js b/assets/scripts/api/local.js index e41b0b6..1e3650b 100644 --- a/assets/scripts/api/local.js +++ b/assets/scripts/api/local.js @@ -88,8 +88,11 @@ const searchLocalFiles = (url, res) => { ++counter /* istanbul ignore next */ if (counter === uniqueNames.length) { + /* istanbul ignore next */ // Saving new data - fs.writeFileSync(join(userInfo().homedir, '.KawAnime', 'locals.json'), JSON.stringify(json), 'utf-8') + process.env.NODE_ENV !== 'KawAnime-test' + ? fs.writeFileSync(join(userInfo().homedir, '.KawAnime', 'locals.json'), JSON.stringify(json), 'utf-8') + : fs.writeFileSync(join(userInfo().homedir, '.KawAnime-test', 'locals.json'), JSON.stringify(json), 'utf-8') console.log('[Local] Successfully saved data.') sendFiles(json, files, res) diff --git a/assets/scripts/api/main.js b/assets/scripts/api/main.js index 1719b84..d888320 100644 --- a/assets/scripts/api/main.js +++ b/assets/scripts/api/main.js @@ -177,7 +177,6 @@ const route = (nuxt) => { openInBrowser(process.nuxtURL, res) break - /* istanbul ignore next */ default: nuxt.render(req, res) break diff --git a/package.json b/package.json index ffc1d4a..1d07898 100755 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "license": "MIT", "scripts": { "dev": "cross-env NODE_ENV=development electron .", + "cloc": "cloc $(git ls-files | grep -vE \".mkv|mp4\")", "test:server": "nyc ava --verbose --serial test/server.test.js", "test:front": "nightwatch", "test": "standard --fix && npm test:front && npm test:server", @@ -102,6 +103,12 @@ "**/*.test.js", "**/node_modules/**", "**/openExternal.js" - ] + ], + "watermarks": { + "lines": [80, 95], + "functions": [80, 95], + "branches": [80, 95], + "statements": [80, 95] + } } } diff --git a/test/server.test.js b/test/server.test.js index c6d683c..6d73356 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -20,7 +20,7 @@ let server = null const uri = 'http://localhost:4000' const DIR = join(userInfo().homedir, '.KawAnime-test') -let kawAnimeFilesPath = { +const kawAnimeFilesPath = { local: join(DIR, 'locals.json'), history: join(DIR, 'history.json'), watchList: join(DIR, 'lists.json'), @@ -30,7 +30,7 @@ let kawAnimeFilesPath = { // Init Nuxt.js and create a server listening on localhost:4000 test.before('Init Nuxt.js', async () => { /** - * Removing potentially existing .KawAnime directory + * Creating .KawAnime-test directory and necessary files */ const initFile = require(join(__dirname, '..', 'assets', 'scripts', 'api', 'main.js')) @@ -327,11 +327,13 @@ test('/downloader exits and render HTML', async t => { t.true(html.includes('Download!')) }) -test('/index exits and render HTML', async t => { - let context = {} - const { html } = await nuxt.renderRoute('/', context) +test('/ route exits and returns HTML (axios)', async t => { + const { data, status } = await axios.get(`${uri}/`) - t.true(html.includes('少々お待ち下さいね〜')) + t.is(status, 200) + + t.true(data.includes('かわニメ')) + t.true(data.includes('少々お待ち下さいね〜')) }) test('/seasons exits and render HTML', async t => {