From 5868cd59b804a93aedf0cfdd82aef632f4466298 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sun, 13 Mar 2016 01:41:55 +0200 Subject: [PATCH] unit tests added for getMainFile --- test/plugins/bundle-service/get-main-file.js | 74 ++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 test/plugins/bundle-service/get-main-file.js diff --git a/test/plugins/bundle-service/get-main-file.js b/test/plugins/bundle-service/get-main-file.js new file mode 100644 index 0000000..406d5a5 --- /dev/null +++ b/test/plugins/bundle-service/get-main-file.js @@ -0,0 +1,74 @@ +'use strict' +const describe = require('mocha').describe +const it = require('mocha').it +const expect = require('chai').expect + +const getMainFile = require('../../../app/plugins/bundle-service/get-main-file') + +describe('getMainFile', () => { + describe('js', () => { + it('should get main file from package.json', () => { + const mainFile = getMainFile({ + extension: 'js', + packageJSON: { + main: 'foo.js', + }, + }) + + expect(mainFile).to.eq('foo.js') + }) + + it('should get main file from package.json and add extension if missing', () => { + const mainFile = getMainFile({ + extension: 'js', + packageJSON: { + main: 'foo', + }, + }) + + expect(mainFile).to.eq('foo.js') + }) + + it('should get default main file when none in package.json', () => { + const mainFile = getMainFile({ + extension: 'js', + packageJSON: {}, + }) + + expect(mainFile).to.eq('index.js') + }) + }) + + describe('css', () => { + it('should get main file from package.json', () => { + const mainFile = getMainFile({ + extension: 'css', + packageJSON: { + style: 'foo.css', + }, + }) + + expect(mainFile).to.eq('foo.css') + }) + + it('should get main file from package.json and add extension if missing', () => { + const mainFile = getMainFile({ + extension: 'css', + packageJSON: { + style: 'foo', + }, + }) + + expect(mainFile).to.eq('foo.css') + }) + + it('should get default main file when none in package.json', () => { + const mainFile = getMainFile({ + extension: 'css', + packageJSON: {}, + }) + + expect(mainFile).to.eq('index.css') + }) + }) +})