Skip to content

Commit

Permalink
ユニットテスト周りの調整・修正 refs #21
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrovers committed Mar 7, 2021
1 parent c3731c1 commit cf2e3ad
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 87 deletions.
38 changes: 22 additions & 16 deletions frontend/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,36 @@

module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
basePath: "",
frameworks: ["jasmine", "@angular-devkit/build-angular"],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
require("karma-jasmine"),
require("karma-chrome-launcher"),
require("karma-mocha-reporter"),
require("karma-coverage"),
require("@angular-devkit/build-angular/plugins/karma"),
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/frontend'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
coverageReporter: {
dir: require("path").join(__dirname, "./coverage/frontend"),
subdir: ".",
reporters: [{ type: "html" }, { type: "text-summary" }],
},
reporters: ['progress', 'kjhtml'],
reporters: ["mocha"],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
browsers: ["ChromeHeadlessCI"],
customLaunchers: {
ChromeHeadlessCI: {
base: "ChromeHeadless",
flags: ["--no-sandbox"],
},
},
singleRun: true,
restartOnFileChange: true,
});
};
79 changes: 47 additions & 32 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@
"@angular/language-service": "~11.0.9",
"@nguniversal/builders": "^11.0.1",
"@types/express": "^4.17.0",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.6.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.1.1",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-coverage": "^2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"karma-mocha-reporter": "^2.2.5",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
Expand Down
33 changes: 10 additions & 23 deletions frontend/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
import { TestBed, waitForAsync } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';

import { AppComponent } from './app.component';
import { MaterialModule } from './material/material.module';

describe('AppComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
AppComponent
],
}).compileComponents();
}));
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule, MaterialModule],
declarations: [AppComponent],
}).compileComponents();
})
);

it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});

it(`should have as title 'frontend'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('frontend');
});

it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(compiled.querySelector('.content span').textContent).toContain('frontend app is running!');
});
});
7 changes: 4 additions & 3 deletions frontend/src/app/footer/footer.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { MaterialModule } from '../material/material.module';
import { FooterComponent } from './footer.component';

describe('FooterComponent', () => {
Expand All @@ -8,9 +9,9 @@ describe('FooterComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ FooterComponent ]
})
.compileComponents();
imports: [MaterialModule],
declarations: [FooterComponent],
}).compileComponents();
});

beforeEach(() => {
Expand Down
22 changes: 15 additions & 7 deletions frontend/src/app/nav/nav.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';

import { MaterialModule } from '../material/material.module';

import { NavComponent } from './nav.component';

// test stub
@Component({ selector: 'app-footer', template: '' })
class FooterComponent {}

describe('NavComponent', () => {
let component: NavComponent;
let fixture: ComponentFixture<NavComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ NavComponent ]
})
.compileComponents();
}));
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RouterTestingModule, MaterialModule],
declarations: [NavComponent, FooterComponent],
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(NavComponent);
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/app/top/top.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { MaterialModule } from '../material/material.module';
import { TopComponent } from './top.component';

describe('TopComponent', () => {
Expand All @@ -8,9 +9,9 @@ describe('TopComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ TopComponent ]
})
.compileComponents();
imports: [MaterialModule],
declarations: [TopComponent],
}).compileComponents();
});

beforeEach(() => {
Expand Down

0 comments on commit cf2e3ad

Please sign in to comment.