test: move testing-related files into test dir

This commit is contained in:
Jason Dreyzehner 2018-02-15 18:34:06 -05:00
parent 8cc3aef805
commit e86c83575b
26 changed files with 36 additions and 43 deletions

View File

@ -12,7 +12,7 @@
"main": "app/main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "../tsconfig.json",
"tsconfig": "./tsconfig.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"scripts": [],
@ -25,7 +25,7 @@
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
"config": "test/protractor.conf.js"
}
},
"lint": [
@ -34,13 +34,13 @@
"exclude": "**/node_modules/**"
},
{
"project": "e2e/tsconfig.e2e.json",
"project": "test/e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
"config": "test/karma.conf.js"
},
"codeCoverage": {
"exclude": [

8
.gitignore vendored
View File

@ -31,10 +31,10 @@ src/assets/i18n/crowdin_api_key.txt
src/index.html
src/manifest.json
test/latest
test/diffs
test/report.html
test/report.json
test/visual/latest
test/visual/diffs
test/visual/report.html
test/visual/report.json
junitresults.xml
.sourcemaps/

View File

@ -36,9 +36,9 @@
"test": "test:lint && npm run test:ci && npm run e2e:capture-latest && npm run test:visual",
"test:coverage": "ng test --code-coverage",
"test:ci": "ng test --watch=false --code-coverage --no-progress",
"test:lint": "tslint --project . --format codeFrame && tslint '{e2e,test,electron,src}/**/*.ts' --format codeFrame && prettier --list-different '{*,**/*}.{js,ts,md,json,scss}'",
"test:visual": "cd test && reg-cli latest approved diffs --report report.html --json report.json --enableAntialias --thresholdRate 0.005",
"fix:tslint": "tslint --fix --project . && tslint --fix '{e2e,test,electron,src}/**/*.ts'",
"test:lint": "tslint --project . --format codeFrame && tslint '{test,electron,src}/**/*.ts' --format codeFrame && prettier --list-different '{*,**/*}.{js,ts,md,json,scss}'",
"test:visual": "cd test/visual && reg-cli latest approved diffs --report report.html --json report.json --enableAntialias --thresholdRate 0.005",
"fix:tslint": "tslint --fix --project . && tslint --fix '{test,electron,src}/**/*.ts'",
"fix:prettier": "prettier --write '{*,**/*}.{js,ts,md,json,scss}'",
"e2e": "npm run ionic:build && npm run e2e:test",
"e2e:test": "protractor",

View File

@ -10,7 +10,7 @@ exports.config = {
allScriptsTimeout: 11000,
jasmineNodeOpts: { defaultTimeoutInterval: 1000 * 60 * 10 },
maxSessions: 4,
specs: ['./e2e/**/*.e2e-spec.ts'],
specs: ['test/e2e/**/*.e2e-spec.ts'],
// Available deviceNames for mobileEmulation: https://chromium.googlesource.com/chromium/src/+/master/third_party/WebKit/Source/devtools/front_end/emulated_devices/module.json
multiCapabilities: [
{
@ -104,7 +104,7 @@ exports.config = {
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
project: 'test/e2e/tsconfig.e2e.json'
});
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(

View File

@ -1,14 +1,16 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
// tslint:disable:ordered-imports
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
// tslint:enable:ordered-imports
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { getTestBed, TestBed } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
@ -18,10 +20,10 @@ import {
App,
Config,
DeepLinker,
DomController,
Form,
IonicModule,
Keyboard,
DomController,
MenuController,
NavController,
Platform
@ -42,24 +44,23 @@ context.keys().map(context);
export class TestUtils {
public static beforeEachCompiler(
components: Array<any>
components: any[]
): Promise<{ fixture: any; instance: any }> {
return TestUtils.configureIonicTestingModule(components)
.compileComponents()
.then(() => {
let fixture: any = TestBed.createComponent(components[0]);
const fixture: any = TestBed.createComponent(components[0]);
return {
fixture: fixture,
fixture,
instance: fixture.debugElement.componentInstance
};
});
}
public static configureIonicTestingModule(
components: Array<any>
): typeof TestBed {
public static configureIonicTestingModule(components: any[]): typeof TestBed {
return TestBed.configureTestingModule({
declarations: [...components],
imports: [FormsModule, IonicModule, ReactiveFormsModule, TranslateModule],
providers: [
App,
Form,
@ -70,8 +71,7 @@ export class TestUtils {
{ provide: Platform, useFactory: () => PlatformMock.instance() },
{ provide: Config, useFactory: () => ConfigMock.instance() },
{ provide: DeepLinker, useFactory: () => ConfigMock.instance() }
],
imports: [FormsModule, IonicModule, ReactiveFormsModule, TranslateModule]
]
});
}
@ -80,7 +80,7 @@ export class TestUtils {
if (el.fireEvent) {
el.fireEvent('on' + etype);
} else {
let evObj: any = document.createEvent('Events');
const evObj: any = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}

View File

@ -1,20 +1,12 @@
{
"extends": "../tsconfig.ng-cli.json",
"extends": "../test/tsconfig.ng-cli.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"baseUrl": "./",
"module": "commonjs",
"target": "es5",
"types": [
"jasmine",
"node"
]
"types": ["jasmine", "node"]
},
"files": [
"test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
"files": ["test.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}

View File

@ -5,9 +5,9 @@ import * as mkdirp from 'mkdirp';
const distribution: string = JSON.parse(
readFileSync('src/assets/appConfig.json', 'utf8')
)['packageName'];
).packageName;
const dir = join('test', 'latest', distribution);
const dir = join('test', 'visual', 'latest', distribution);
// create dir if it doesn't exist
mkdirp(dir);
@ -25,7 +25,7 @@ document.body.appendChild(elem);
export async function takeScreenshot(name: string) {
browser.executeScript(jsToInjectCSSHack);
const config = await browser.getProcessedConfig();
const deviceName = config['capabilities']['name'];
const deviceName = config['capabilities'].name;
const pngData = await browser.takeScreenshot();
const path = join(dir, `${name}_${deviceName}.png`);
writeFile(path, pngData, { encoding: 'base64' }, err => {

View File

@ -3,7 +3,7 @@
module.exports = function(config) {
config.set({
basePath: '',
basePath: '..',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),

View File

@ -1,14 +1,14 @@
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": ["node_modules/@types"],
"typeRoots": ["../node_modules/@types"],
"lib": ["es2017", "dom"]
}
}

View File

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View File

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 74 KiB

View File

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 57 KiB

View File

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View File

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

View File

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 43 KiB

View File

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 71 KiB

View File

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

View File

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 82 KiB

View File

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 67 KiB

View File

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 60 KiB

View File

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

View File

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View File

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 79 KiB

View File

@ -1,6 +1,7 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"interface-name": [true, "never-prefix"]
"interface-name": [true, "never-prefix"],
"no-submodule-imports": [true, "zone.js", "@angular"]
}
}