Skip to content

Commit

Permalink
build: move test files to src/__tests__ in example apps
Browse files Browse the repository at this point in the history
- Source files are compiled from `src/{foo}` to `dist/{foo}`, the same
  pattern is applied to test files too.

- Both TypeScript sources and JavaScript output are stored in the same
  path relative to project root. This makes it much easier to refer
  to test fixtures.

This is a follow-up for 066d525.
  • Loading branch information
bajtos committed Jan 31, 2019
1 parent f946d48 commit c1d12eb
Show file tree
Hide file tree
Showing 47 changed files with 68 additions and 71 deletions.
6 changes: 3 additions & 3 deletions examples/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"node": ">=8.9"
},
"scripts": {
"acceptance": "lb-mocha \"dist/test/acceptance/**/*.js\"",
"acceptance": "lb-mocha \"dist/__tests__/acceptance/**/*.js\"",
"build:apidocs": "lb-apidocs",
"build": "lb-tsc es2017 --outDir dist",
"build:watch": "lb-tsc es2017 --outDir dist --watch",
Expand All @@ -21,9 +21,9 @@
"tslint": "lb-tslint",
"tslint:fix": "npm run tslint -- --fix",
"pretest": "npm run clean && npm run build",
"test": "lb-mocha --allow-console-logs \"dist/test\"",
"test": "lb-mocha --allow-console-logs \"dist/__tests__/**/*.js\"",
"posttest": "npm run lint",
"test:dev": "lb-mocha --allow-console-logs dist/test/**/*.js && npm run posttest",
"test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js && npm run posttest",
"prestart": "npm run build",
"start": "node ."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
expect,
givenHttpServerConfig,
} from '@loopback/testlab';
import {HelloWorldApplication} from '../../src/application';
import {HelloWorldApplication} from '../../application';

describe('Application', () => {
let app: HelloWorldApplication;
Expand Down
4 changes: 2 additions & 2 deletions examples/hello-world/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "@loopback/build/config/tsconfig.common.json",
"compilerOptions": {
"rootDir": "."
"rootDir": "src"
},
"include": ["index.ts", "src", "test"]
"include": ["src"]
}
4 changes: 2 additions & 2 deletions examples/log-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"tslint": "lb-tslint",
"tslint:fix": "npm run tslint -- --fix",
"pretest": "npm run clean && npm run build",
"test": "lb-mocha \"dist/test/unit/**/*.js\" \"dist/test/acceptance/**/*.js\"",
"test": "lb-mocha \"dist/__tests__/**/*.js\"",
"posttest": "npm run lint",
"test:dev": "lb-mocha --allow-console-logs dist/test/**/*.js && npm run posttest",
"test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js && npm run posttest",
"verify": "npm pack && tar xf *example-log-extension*.tgz && tree package && npm run clean"
},
"repository": {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions examples/log-extension/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "@loopback/build/config/tsconfig.common.json",
"compilerOptions": {
"rootDir": "."
"rootDir": "src"
},
"include": ["index.ts", "src", "test"]
"include": ["src"]
}
4 changes: 2 additions & 2 deletions examples/rpc-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"tslint": "lb-tslint",
"tslint:fix": "npm run tslint -- --fix",
"pretest": "npm run clean && npm run build",
"test": "lb-mocha dist/test",
"test": "lb-mocha dist/__tests__/**/*.js",
"posttest": "npm run lint",
"test:dev": "lb-mocha --allow-console-logs dist/test/**/*.js && npm run posttest",
"test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js && npm run posttest",
"prestart": "npm run build",
"start": "node ."
},
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {GreetController} from '../../../src/controllers';
import {GreetController} from '../../../controllers';
import {expect} from '@loopback/testlab';

describe('greet.controller', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// License text available at https://opensource.org/licenses/MIT

import * as express from 'express';
import {RPCServer} from '../../src/rpc.server';
import {routeHandler} from '../../src/rpc.router';
import {RPCServer} from '../../rpc.server';
import {routeHandler} from '../../rpc.router';
import {expect, sinon} from '@loopback/testlab';

describe('rpcRouter', () => {
Expand Down
4 changes: 2 additions & 2 deletions examples/soap-calculator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
"tslint": "lb-tslint",
"tslint:fix": "npm run tslint -- --fix",
"pretest": "npm run clean && npm run build",
"test": "lb-mocha \"dist/test\"",
"test": "lb-mocha \"dist/__tests__/**/*.js\"",
"posttest": "npm run lint",
"test:dev": "lb-mocha --allow-console-logs dist/test/**/*.js && npm run posttest",
"test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js && npm run posttest",
"prestart": "npm run build",
"start": "node ."
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Client, createRestAppClient, expect} from '@loopback/testlab';
import {SoapCalculatorApplication} from '../../src/application';
import {SoapCalculatorApplication} from '../../application';

describe('Application', function() {
let app: SoapCalculatorApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CalculatorDataSource} from '../src/datasources/calculator.datasource';
import {CalculatorDataSource} from '../datasources/calculator.datasource';

export async function givenAConnectedDataSource(): Promise<
CalculatorDataSource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
CalculatorService,
CalculatorParameters,
} from '../../../src/services/calculator.service';
import {CalculatorServiceProvider} from '../../../src/services/calculator.service';
} from '../../../services/calculator.service';
import {CalculatorServiceProvider} from '../../../services/calculator.service';
import {givenAConnectedDataSource} from '../../helpers';

import {expect} from '@loopback/testlab';
Expand Down
2 changes: 1 addition & 1 deletion examples/soap-calculator/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class SoapCalculatorApplication extends BootMixin(
this.sequence(MySequence);

// Set up default home page
this.static('/', path.join(__dirname, '../../public'));
this.static('/', path.join(__dirname, '../public'));

this.component(RestExplorerComponent);

Expand Down
4 changes: 2 additions & 2 deletions examples/soap-calculator/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "@loopback/build/config/tsconfig.common.json",
"compilerOptions": {
"rootDir": "."
"rootDir": "src"
},
"include": ["index.ts", "src", "test"]
"include": ["src"]
}
4 changes: 2 additions & 2 deletions examples/todo-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"tslint": "lb-tslint",
"tslint:fix": "npm run tslint -- --fix",
"pretest": "npm run build",
"test": "lb-mocha \"dist/test/*/**/*.js\"",
"test:dev": "lb-mocha --allow-console-logs dist/test/**/*.js && npm run posttest",
"test": "lb-mocha \"dist/__tests__/**/*.js\"",
"test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js && npm run posttest",
"verify": "npm pack && tar xf loopback-todo-list*.tgz && tree package && npm run clean",
"migrate": "node ./dist/src/migrate",
"prestart": "npm run build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import {
givenHttpServerConfig,
toJSON,
} from '@loopback/testlab';
import {TodoListApplication} from '../../src/application';
import {TodoList, TodoListImage} from '../../src/models/';
import {
TodoListRepository,
TodoListImageRepository,
} from '../../src/repositories/';
import {TodoListApplication} from '../../application';
import {TodoList, TodoListImage} from '../../models/';
import {TodoListRepository, TodoListImageRepository} from '../../repositories/';
import {givenTodoListImage, givenTodoList} from '../helpers';

describe('TodoListApplication', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
givenHttpServerConfig,
toJSON,
} from '@loopback/testlab';
import {TodoListApplication} from '../../src/application';
import {Todo, TodoList} from '../../src/models/';
import {TodoListRepository, TodoRepository} from '../../src/repositories/';
import {TodoListApplication} from '../../application';
import {Todo, TodoList} from '../../models/';
import {TodoListRepository, TodoRepository} from '../../repositories/';
import {givenTodo, givenTodoList} from '../helpers';

describe('TodoListApplication', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
givenHttpServerConfig,
toJSON,
} from '@loopback/testlab';
import {TodoListApplication} from '../../src/application';
import {TodoList} from '../../src/models/';
import {TodoListRepository} from '../../src/repositories/';
import {TodoListApplication} from '../../application';
import {TodoList} from '../../models/';
import {TodoListRepository} from '../../repositories/';
import {givenTodoList} from '../helpers';

describe('TodoListApplication', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
givenHttpServerConfig,
toJSON,
} from '@loopback/testlab';
import {TodoListApplication} from '../../src/application';
import {Todo, TodoList} from '../../src/models/';
import {TodoRepository, TodoListRepository} from '../../src/repositories/';
import {TodoListApplication} from '../../application';
import {Todo, TodoList} from '../../models/';
import {TodoRepository, TodoListRepository} from '../../repositories/';
import {givenTodo, givenTodoList} from '../helpers';

describe('TodoListApplication', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {Todo, TodoList, TodoListImage} from '../src/models';
import {Todo, TodoList, TodoListImage} from '../models';

/*
==============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
sinon,
StubbedInstanceWithSinonAccessor,
} from '@loopback/testlab';
import {TodoListTodoController} from '../../../src/controllers';
import {Todo, TodoList} from '../../../src/models';
import {TodoListRepository} from '../../../src/repositories';
import {TodoListTodoController} from '../../../controllers';
import {Todo, TodoList} from '../../../models';
import {TodoListRepository} from '../../../repositories';
import {givenTodo, givenTodoList} from '../../helpers';

describe('TodoController', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
sinon,
StubbedInstanceWithSinonAccessor,
} from '@loopback/testlab';
import {TodoListController} from '../../../src/controllers';
import {TodoList} from '../../../src/models';
import {TodoListRepository} from '../../../src/repositories';
import {TodoListController} from '../../../controllers';
import {TodoList} from '../../../models';
import {TodoListRepository} from '../../../repositories';
import {givenTodoList} from '../../helpers';

describe('TodoController', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
sinon,
StubbedInstanceWithSinonAccessor,
} from '@loopback/testlab';
import {TodoController} from '../../../src/controllers';
import {Todo} from '../../../src/models';
import {TodoRepository} from '../../../src/repositories';
import {TodoController} from '../../../controllers';
import {Todo} from '../../../models';
import {TodoRepository} from '../../../repositories';
import {givenTodo} from '../../helpers';

describe('TodoController', () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/todo-list/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class TodoListApplication extends BootMixin(
this.sequence(MySequence);

// Set up default home page
this.static('/', path.join(__dirname, '../../public'));
this.static('/', path.join(__dirname, '../public'));

this.component(RestExplorerComponent);

Expand Down
2 changes: 1 addition & 1 deletion examples/todo-list/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"compilerOptions": {
"rootDir": "."
},
"include": ["index.ts", "src", "test"]
"include": ["src"]
}
4 changes: 2 additions & 2 deletions examples/todo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"tslint": "lb-tslint",
"tslint:fix": "npm run tslint -- --fix",
"pretest": "npm run build",
"test": "lb-mocha \"dist/test/*/**/*.js\"",
"test:dev": "lb-mocha --allow-console-logs dist/test/**/*.js && npm run posttest",
"test": "lb-mocha \"dist/__tests__/**/*.js\"",
"test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js && npm run posttest",
"verify": "npm pack && tar xf loopback-todo*.tgz && tree package && npm run clean",
"migrate": "node ./dist/src/migrate",
"prestart": "npm run build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
givenHttpServerConfig,
toJSON,
} from '@loopback/testlab';
import {TodoListApplication} from '../../src/application';
import {Todo} from '../../src/models/';
import {TodoRepository} from '../../src/repositories/';
import {TodoListApplication} from '../../application';
import {Todo} from '../../models/';
import {TodoRepository} from '../../repositories/';
import {
aLocation,
getProxiedGeoCoderConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import {HttpCachingProxy} from '@loopback/http-caching-proxy';
import {merge} from 'lodash';
import * as path from 'path';
import {Todo} from '../src/models/index';
import {GeoPoint} from '../src/services/geocoder.service';
import * as GEO_CODER_CONFIG from '../src/datasources/geocoder.datasource.json';
import {Todo} from '../models/index';
import {GeoPoint} from '../services/geocoder.service';
import * as GEO_CODER_CONFIG from '../datasources/geocoder.datasource.json';

/*
==============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
// License text available at https://opensource.org/licenses/MIT

import {expect} from '@loopback/testlab';
import {GeocoderService, GeocoderServiceProvider} from '../../../src/services';
import {GeocoderService, GeocoderServiceProvider} from '../../../services';
import {
HttpCachingProxy,
givenCachingProxy,
getProxiedGeoCoderConfig,
} from '../../helpers';
import {GeocoderDataSource} from '../../../src/datasources/geocoder.datasource';
import {GeocoderDataSource} from '../../../datasources/geocoder.datasource';

describe('GeoLookupService', function() {
// tslint:disable-next-line:no-invalid-this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
sinon,
StubbedInstanceWithSinonAccessor,
} from '@loopback/testlab';
import {TodoController} from '../../../src/controllers';
import {Todo} from '../../../src/models/index';
import {TodoRepository} from '../../../src/repositories';
import {GeocoderService} from '../../../src/services';
import {TodoController} from '../../../controllers';
import {Todo} from '../../../models/index';
import {TodoRepository} from '../../../repositories';
import {GeocoderService} from '../../../services';
import {aLocation, givenTodo} from '../../helpers';

describe('TodoController', () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/todo/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class TodoListApplication extends BootMixin(
this.sequence(MySequence);

// Set up default home page
this.static('/', path.join(__dirname, '../../public'));
this.static('/', path.join(__dirname, '../public'));

this.component(RestExplorerComponent);

Expand Down
4 changes: 2 additions & 2 deletions examples/todo/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "@loopback/build/config/tsconfig.common.json",
"compilerOptions": {
"rootDir": "."
"rootDir": "src"
},
"include": ["index.ts", "src", "test"]
"include": ["src"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"test:ci": "node packages/build/bin/run-nyc npm run mocha --scripts-prepend-node-path",
"verify:docs": "npm run build:site -- --verify",
"build:site": "./bin/build-docs-site.sh",
"mocha": "node packages/build/bin/run-mocha \"packages/*/dist/test/**/*.js\" \"packages/*/dist/__tests__/**/*.js\" \"examples/*/dist/test/**/*.js\" \"packages/cli/test/**/*.js\" \"packages/build/test/*/*.js\"",
"mocha": "node packages/build/bin/run-mocha \"packages/*/dist/test/**/*.js\" \"packages/*/dist/__tests__/**/*.js\" \"examples/*/dist/__tests__/**/*.js\" \"packages/cli/test/**/*.js\" \"packages/build/test/*/*.js\"",
"posttest": "npm run lint"
},
"config": {
Expand Down

0 comments on commit c1d12eb

Please sign in to comment.