Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move test files to src/__tests__ #82

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"tslint:fix": "npm run tslint -- --fix",
"pretest": "npm run clean && npm run build && npm run docker:start",
"pretest:ci": "npm run build",
"test": "lb-mocha --allow-console-logs \"dist/test\"",
"test:ci": "lb-mocha --allow-console-logs \"dist/test\"",
"test": "lb-mocha --allow-console-logs \"dist/src/__tests__/**/*.js\"",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the similar PR loopbackio/loopback-next#2316, it references dist/__tests__/**/*.js without the src folder in the path, but somehow I cannot get it to work in here.
cc @b-admike

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So with your current changes, in the dist folder, it currently contains two folders: src and recommender. In the PR you referenced, in tsconfig.build.json, this change is made:

"compilerOptions": {
-   "rootDir": "."
+   "rootDir": "src"
},

Now all the files that were originally in the src folder are now the ones in the dist folder. The problem is that if you try to do that here, then it won't include the recommender folder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. that's the problem we're having now. Tried below but still have the same error that "no test files found in dist/tests/**/*.js".

    "rootDirs": ["src", "recommender"]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have more than one directories, they will be created under dist. We need to either make this repo a monorepo or refactor recommender into src.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the original intent of putting recommender folder outside src because it's not part of the LB application? If our ultimate goal is to make this repo a monorepo where each "component" as separate microservices, maybe we'd go for the monorepo option?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing it with @b-admike, I changed my mind. Putting everything into src might be a simpler solution, and we can make this as the monorepo when we're going to make each component as microservices.

@strongloop/loopback-maintainers, thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting everything into src might be a simpler solution, and we can make this as the monorepo when we're going to make each component as microservices.

+1

"test:ci": "lb-mocha --allow-console-logs \"dist/src/__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/src/__tests__/**/*.js && npm run posttest",
"prestart": "npm run build",
"start": "concurrently --kill-others \"npm run start:app\" \"npm run start:recommender\"",
"start:app": "node .",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import {Client, expect} from '@loopback/testlab';
import {ShoppingApplication} from '../..';
import {ShoppingCartRepository} from '../../src/repositories';
import {RedisDataSource} from '../../src/datasources';
import {ShoppingCart, ShoppingCartItem} from '../../src/models';
import {ShoppingCartRepository} from '../../repositories';
import {RedisDataSource} from '../../datasources';
import {ShoppingCart, ShoppingCartItem} from '../../models';
import {setupApplication} from './helper';

describe('ShoppingCartController', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import {supertest, expect} from '@loopback/testlab';
import {ShoppingApplication} from '../..';
import {OrderRepository, UserRepository} from '../../src/repositories';
import {MongoDataSource} from '../../src/datasources';
import {User, Order} from '../../src/models';
import {OrderRepository, UserRepository} from '../../repositories';
import {MongoDataSource} from '../../datasources';
import {User, Order} from '../../models';
import {setupApplication} from './helper';

describe('UserOrderController acceptance tests', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@
import {Client, expect, toJSON} from '@loopback/testlab';
import {Response} from 'superagent';
import {ShoppingApplication} from '../..';
import {UserRepository, OrderRepository} from '../../src/repositories';
import {MongoDataSource} from '../../src/datasources';
import {UserRepository, OrderRepository} from '../../repositories';
import {MongoDataSource} from '../../datasources';
import {setupApplication} from './helper';
import {createRecommendationServer} from '../../recommender';
import {createRecommendationServer} from '../../../recommender';
import {Server} from 'http';
import * as _ from 'lodash';
import {JWTAuthenticationService} from '../../src/services/JWT.authentication.service';
import {
PasswordHasherBindings,
JWTAuthenticationBindings,
} from '../../src/keys';
const recommendations = require('../../recommender/recommendations.json');
import {JWTAuthenticationService} from '../../services/JWT.authentication.service';
import {PasswordHasherBindings, JWTAuthenticationBindings} from '../../keys';
const recommendations = require('../../../recommender/recommendations.json');

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

import {ShoppingCartRepository} from '../../src/repositories';
import {ShoppingCart, ShoppingCartItem} from '../../src/models';
import {ShoppingCartRepository} from '../../repositories';
import {ShoppingCart, ShoppingCartItem} from '../../models';
import {expect} from '@loopback/testlab';
import {RedisDataSource} from '../../src/datasources';
import {RedisDataSource} from '../../datasources';

describe('ShoppingCart KeyValue Repository', () => {
let repo: ShoppingCartRepository;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
// License text available at https://opensource.org/licenses/MIT

import {expect, toJSON} from '@loopback/testlab';
import {MongoDataSource} from '../../src/datasources';
import {JWTAuthenticationService} from '../../src/services/JWT.authentication.service';
import {MongoDataSource} from '../../datasources';
import {JWTAuthenticationService} from '../../services/JWT.authentication.service';
import {ShoppingApplication} from '../..';
import {PasswordHasher} from '../../src/services/hash.password.bcryptjs';
import {UserRepository, OrderRepository} from '../../src/repositories';
import {User} from '../../src/models';
import {PasswordHasher} from '../../services/hash.password.bcryptjs';
import {UserRepository, OrderRepository} from '../../repositories';
import {User} from '../../models';
import * as _ from 'lodash';
import {JsonWebTokenError} from 'jsonwebtoken';
import {HttpErrors} from '@loopback/rest';
import {
PasswordHasherBindings,
JWTAuthenticationBindings,
} from '../../src/keys';
import {PasswordHasherBindings, JWTAuthenticationBindings} from '../../keys';
import {setupApplication} from './helper';

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

import {expect} from '@loopback/testlab';
import {sleep, Task, retry} from '../../src/utils/retry';
import {sleep, Task, retry} from '../../utils/retry';

describe('sleep()', () => {
it('waits for given milliseconds', async () => {
Expand Down
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"extends": "./node_modules/@loopback/build/config/tsconfig.common.json",
"include": [
"src",
"test",
"recommender",
"index.ts"
"recommender"
],
"exclude": [
"node_modules/**",
Expand Down