Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
liam-grace committed Mar 13, 2017
2 parents 9e1b38f + feda354 commit 8ea2ee6
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 81 deletions.
2 changes: 1 addition & 1 deletion packages/composer-playground/config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(config) {
*
* available frameworks: https://npmjs.org/browse/keyword/karma-adapter
*/
frameworks: ['jasmine'],
frameworks: ['jasmine', 'chai', 'sinon', 'sinon-chai'],

// list of files to exclude
exclude: [ ],
Expand Down
43 changes: 33 additions & 10 deletions packages/composer-playground/config/webpack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,39 @@ const ProvidePlugin = require('webpack/lib/ProvidePlugin');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');

/**
* Webpack Constants
*/
const ENV = process.env.ENV = process.env.NODE_ENV = 'test';
const DOCKER = !!process.env.DOCKER;
const DOCKER_COMPOSE = !!process.env.DOCKER_COMPOSE;
const PLAYGROUND_API = process.env.PLAYGROUND_API;
const PLAYGROUND_API = process.env.PLAYGROUND_API || 'playground-api';

/**
* Webpack configuration
*
* See: http://webpack.github.io/docs/configuration.html#cli
*/
module.exports = function (options) {
return {

/**
* Source map for Karma from the help of karma-sourcemap-loader & karma-webpack
*
* Do not change, leave as is or it wont work.
* See: https://github.com/webpack/karma-webpack#source-maps
*/
devtool: 'inline-source-map',

/**
* Options affecting the resolving of modules.
*
* See: http://webpack.github.io/docs/configuration.html#resolve
*/
/*
* Options affecting the resolving of modules.
*
* See: http://webpack.github.io/docs/configuration.html#resolve
*/
resolve: {
/*

/**
* An array of extensions that should be used to resolve modules.
*
* See: http://webpack.github.io/docs/configuration.html#resolve-extensions
Expand All @@ -59,9 +59,11 @@ module.exports = function (options) {
'path': 'browserfs/dist/shims/path.js',
'processGlobal': 'browserfs/dist/shims/process.js',
'bufferGlobal': 'browserfs/dist/shims/bufferGlobal.js',
'bfsGlobal': require.resolve('browserfs')
'bfsGlobal': require.resolve('browserfs'),
sinon: 'sinon/pkg/sinon'
}
},

/**
* Options affecting the normal modules.
*
Expand All @@ -71,6 +73,9 @@ module.exports = function (options) {
* See: https://github.com/AngularClass/angular2-webpack-starter/issues/1188#issuecomment-262872034
*/
module: {

noParse: [/sinon/],

rules: [
/*
* Typescript loader support for .ts and Angular 2 async routes via .async.ts
Expand Down Expand Up @@ -111,6 +116,7 @@ module.exports = function (options) {
presets: [require.resolve('babel-preset-es2015')]
}
},

/**
* Json loader support for *.json files.
*
Expand All @@ -132,6 +138,7 @@ module.exports = function (options) {
loader: ['to-string-loader', 'css-loader'],
exclude: [helpers.root('src/index.html')]
},

/**
* Raw loader support for *.scss files
*
Expand All @@ -142,6 +149,7 @@ module.exports = function (options) {
loader: ['raw-loader', 'sass-loader'],
exclude: [helpers.root('src/index.html')]
},

/**
* Raw loader support for *.html
* Returns file content as string
Expand All @@ -153,6 +161,9 @@ module.exports = function (options) {
loader: 'raw-loader',
exclude: [helpers.root('src/index.html')]
},

{ test: /sinon.*\.js$/, loader: "imports-loader?define=>false,require=>false" },

/**
* Instruments JS files with Istanbul for subsequent code coverage reporting.
* Instrument only testing sources.
Expand All @@ -165,10 +176,10 @@ module.exports = function (options) {
loader: 'istanbul-instrumenter-loader',
include: helpers.root('src'),
exclude: [
/\.ts$/,
/node_modules/
]
},

{
test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
loader: "url-loader?limit=10000&minetype=application/font-woff"
Expand All @@ -189,6 +200,7 @@ module.exports = function (options) {
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader: "url-loader?limit=10000&minetype=image/svg+xml"
},

/**
* BrowserFS has a crap implementation of setImmediate:
* https://github.com/jvilk/BrowserFS/issues/169
Expand All @@ -202,12 +214,14 @@ module.exports = function (options) {
}
]
},

/**
* Add additional plugins to the compiler.
*
* See: http://webpack.github.io/docs/configuration.html#plugins
*/
plugins: [

/**
* Plugin: DefinePlugin
* Description: Define free variables.
Expand All @@ -222,13 +236,15 @@ module.exports = function (options) {
'ENV': JSON.stringify(ENV),
'HMR': false,
'DOCKER': DOCKER,
'DOCKER_COMPOSE': DOCKER_COMPOSE
'DOCKER_COMPOSE': DOCKER_COMPOSE,
'PLAYGROUND_API' : JSON.stringify(PLAYGROUND_API)
/* 'process.env': {
'ENV': JSON.stringify(ENV),
'NODE_ENV': JSON.stringify(ENV),
'HMR': false,
} */
}),

/**
* Plugin: ContextReplacementPlugin
* Description: Provides context to Angular's use of System.import
Expand All @@ -244,6 +260,7 @@ module.exports = function (options) {
// your Angular Async Route paths relative to this root directory
}
),

/**
* Plugin LoaderOptionsPlugin (experimental)
*
Expand All @@ -252,15 +269,20 @@ module.exports = function (options) {
new LoaderOptionsPlugin({
debug: true,
options: {

}
}),

new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
jquery: 'jquery'
}),

new webpack.ProvidePlugin({ BrowserFS: 'bfsGlobal', process: 'processGlobal', Buffer: 'bufferGlobal' })

],

/**
* Include polyfills or mocks for various node stuff
* Description: Node configuration
Expand All @@ -275,5 +297,6 @@ module.exports = function (options) {
clearImmediate: false,
setImmediate: true
}

};
}
13 changes: 11 additions & 2 deletions packages/composer-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@
"@angularclass/conventions-loader": "^1.0.13",
"@angularclass/hmr": "^1.2.2",
"@angularclass/hmr-loader": "^3.0.2",
"@types/chai": "^3.4.35",
"@types/dropboxjs": "^0.0.29",
"@types/filesystem": "^0.0.28",
"@types/hammerjs": "^2.0.34",
"@types/jasmine": "^2.5.40",
"@types/left-pad": "^1.1.0",
"@types/node": "^7.0.5",
"@types/selenium-webdriver": "^2.53.38",
"@types/sinon": "^1.16.35",
"@types/sinon-chai": "^2.7.27",
"@types/source-map": "^0.5.0",
"@types/uglify-js": "^2.6.28",
"@types/webpack": "^2.1.0",
Expand All @@ -119,6 +122,7 @@
"babel-preset-es2015": "^6.18.0",
"bootstrap": "4.0.0-alpha.5",
"browserfs": "^1.1.0",
"chai": "^3.5.0",
"codelyzer": "^2.0.0-beta.4",
"codemirror": "^5.22.0",
"composer-admin": "^0.5.2",
Expand Down Expand Up @@ -148,11 +152,14 @@
"jsonata": "^1.1.1",
"jszip": "^3.1.3",
"karma": "^1.3.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.1.0",
"karma-mocha-reporter": "^2.2.1",
"karma-remap-coverage": "^0.1.4",
"karma-sinon": "^1.0.5",
"karma-sinon-chai": "^1.2.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.2",
"left-pad": "^1.1.3",
Expand All @@ -171,6 +178,8 @@
"script-ext-html-webpack-plugin": "^1.3.5",
"semver": "^5.3.0",
"setimmediate": "^1.0.5",
"sinon": "^1.17.7",
"sinon-chai": "^2.8.0",
"source-map-loader": "^0.1.5",
"spa-http-server": "^0.9.0",
"string-replace-loader": "^1.0.5",
Expand All @@ -185,10 +194,10 @@
"tslint": "^4.2.0",
"tslint-loader": "^3.3.0",
"typedoc": "^0.5.3",
"typescript": "^2.1.4",
"typescript": "^2.2.1",
"url-loader": "^0.5.7",
"v8-lazy-parse-webpack-plugin": "^0.3.0",
"webpack": "^2.1.0-beta.22",
"webpack": "^2.2.1",
"webpack-dev-middleware": "^1.9.0",
"webpack-dev-server": "^2.1.0-beta.11",
"webpack-md5-hash": "^0.0.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ describe('AboutComponent', () => {

it ('Should display the correct title for the AboutComponent', () => {
fixture.detectChanges();
expect(el.textContent).toContain('About');
el.textContent.should.equal('About');
});

it ('Should call getVersions when the component is created', fakeAsync(() => {
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(fixture.componentInstance.playground).toBe(MOCK_RETURN.playground);
fixture.componentInstance.playground.should.equal(MOCK_RETURN.playground);
}));
});
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {DebugElement} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';

import { BehaviorSubject, Subject } from 'rxjs/Rx';
import {BehaviorSubject, Subject} from 'rxjs/Rx';

import { BusinessNetworkDefinition, AdminConnection } from 'composer-admin';
import { ModelFile } from 'composer-common';
import {BusinessNetworkDefinition, AdminConnection} from 'composer-admin';
import {ModelFile} from 'composer-common';

import { AddFileComponent } from './add-file.component';
import { FileImporterComponent } from './../file-importer';
import { FileDragDropDirective } from './../directives/file-drag-drop';
import {AddFileComponent} from './add-file.component';
import {FileImporterComponent} from './../file-importer';
import {FileDragDropDirective} from './../directives/file-drag-drop';

import { AdminService } from '../services/admin.service';
import { ClientService } from '../services/client.service';
import { AlertService } from '../services/alert.service';
import {AdminService} from '../services/admin.service';
import {ClientService} from '../services/client.service';
import {AlertService} from '../services/alert.service';

import * as sinon from 'sinon';

const fs = require('fs');


class MockAdminService {
constructor() {}
constructor() {
}

getAdminConnection(): AdminConnection {
return new AdminConnection();
Expand Down Expand Up @@ -75,8 +78,8 @@ describe('AddFileComponent', () => {
FormsModule
],
providers: [
{ provide: AdminService, useClass: MockAdminService },
{ provide: AlertService , useClass: MockAlertService },
{provide: AdminService, useClass: MockAdminService},
{provide: AlertService, useClass: MockAlertService},
NgbActiveModal
]
});
Expand All @@ -88,35 +91,31 @@ describe('AddFileComponent', () => {

describe('#fileDetected', () => {
it('should change this.expandInput to true', () => {
expect(() => {
component.fileDetected();
}).not.toThrow();
expect(component.expandInput).toBe(true);
component.fileDetected();
component.expandInput.should.equal(true);
});
});

describe('#fileLeft', () => {
it('should change this.expectedInput to false', () => {
component.fileLeft();
expect(component.expandInput).toBe(false);
component.expandInput.should.equal(false)
});
});

describe('#fileAccepted', () => {
it('should set this.currentFile to a ModelFile', () => {
it('should set this.currentFile to a ModelFile', async(() => {

let b = new Blob(['/**CTO File*/'], { type: 'text/plain'});
let b = new Blob(['/**CTO File*/'], {type: 'text/plain'});
let file = new File([b], 'newfile.cto');

return component.fileAccepted(file)
.then(() => {
expect(component.createModel).toHaveBeenCalled();
})
.catch((err) => {
spyOn(component, 'fileRejected');
expect(component.fileRejected).not.toHaveBeenCalled();
});
});
let createMock = sinon.stub(component, 'createModel');

component.fileAccepted(file)
.then(() => {
component.createModel.should.have.been.called;
});
}));

// it('should set this.currentFile to a ScriptFile', () => {
// spyOn(component, 'createScript');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe('ConfirmComponent', () => {
fixture = TestBed.createComponent(ConfirmComponent);
component = fixture.componentInstance;
});

it('should create', () => {
expect(component).toBeTruthy();
component.should.be.ok;
});
});
Loading

0 comments on commit 8ea2ee6

Please sign in to comment.