diff --git a/benchmark/package.json b/benchmark/package.json index 01d82f0d20c7..172b3a1c41e3 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -18,7 +18,7 @@ "pretest": "npm run clean && npm run build", "test": "lb-mocha \"dist/__tests__\"", "prestart": "npm run build", - "benchmark:routing": "node ./dist/src/rest-routing/routing-table", + "benchmark:routing": "node ./dist/rest-routing/routing-table", "start": "node ." }, "repository": { @@ -30,9 +30,9 @@ "README.md", "index.js", "index.d.ts", - "dist/src", - "dist/index*", - "src" + "dist", + "src", + "!*/__tests__" ], "dependencies": { "@loopback/example-todo": "^1.4.2", diff --git a/benchmark/tsconfig.build.json b/benchmark/tsconfig.build.json index f8bd0f50ef8f..6e15e4be4f6f 100644 --- a/benchmark/tsconfig.build.json +++ b/benchmark/tsconfig.build.json @@ -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"] } diff --git a/docs/site/Application-generator.md b/docs/site/Application-generator.md index 9d087fecb2d7..7607d291cc6e 100644 --- a/docs/site/Application-generator.md +++ b/docs/site/Application-generator.md @@ -76,6 +76,7 @@ the following files and directories: ```text . ├── src/ +| ├── __tests__/ | ├── controllers/ | | └── ping.controller.ts | ├── datasources/ @@ -84,7 +85,6 @@ the following files and directories: | ├── application.ts | ├── index.ts | └── sequence.ts -├── test/ └── package.json ``` diff --git a/docs/site/Controllers.md b/docs/site/Controllers.md index 483f3bd4ff31..8570ee662afa 100644 --- a/docs/site/Controllers.md +++ b/docs/site/Controllers.md @@ -239,11 +239,11 @@ codes is found The example below shows the previous controller revamped with `HttpErrors` along with a test to verify that the error is thrown properly. -{% include code-caption.html content="test/integration/controllers/hello.controller.integration.ts" %} +{% include code-caption.html content="src/__tests__/integration/controllers/hello.controller.integration.ts" %} ```ts -import {HelloController} from '../../../src/controllers'; -import {HelloRepository} from '../../../src/repositories'; +import {HelloController} from '../../../controllers'; +import {HelloRepository} from '../../../repositories'; import {testdb} from '../../fixtures/datasources/testdb.datasource'; import {expect} from '@loopback/testlab'; import {HttpErrors} from '@loopback/rest'; diff --git a/docs/site/DEVELOPING.md b/docs/site/DEVELOPING.md index 5445b2170970..09026d83dac7 100644 --- a/docs/site/DEVELOPING.md +++ b/docs/site/DEVELOPING.md @@ -148,9 +148,9 @@ tests (unit, acceptance and integration), with the convention Examples are: ``` -test/acceptance/application.acceptance.ts -test/integration/user.controller.integration.ts -test/unit/application.unit.ts +src/__tests__/acceptance/application.acceptance.ts +src/__tests__/integration/user.controller.integration.ts +src/__tests__/unit/application.unit.ts ``` ## API Documentation diff --git a/docs/site/Defining-the-API-using-design-first-approach.shelved.md b/docs/site/Defining-the-API-using-design-first-approach.shelved.md index d1728b7ead56..89dc7564a798 100644 --- a/docs/site/Defining-the-API-using-design-first-approach.shelved.md +++ b/docs/site/Defining-the-API-using-design-first-approach.shelved.md @@ -408,7 +408,7 @@ module provides a helper function for checking whether a specification conforms to OpenAPI Spec. Just add a new Mocha test that calls this helper function to the test suite: -{% include code-caption.html content="test/acceptance/api-spec.acceptance.ts" %} +{% include code-caption.html content="src/__tests__/acceptance/api-spec.acceptance.ts" %} ```ts import {validateApiSpec} from '@loopback/testlab'; diff --git a/docs/site/Implementing-features.shelved.md b/docs/site/Implementing-features.shelved.md index 901fa0eb3fcc..237c9e862d2d 100644 --- a/docs/site/Implementing-features.shelved.md +++ b/docs/site/Implementing-features.shelved.md @@ -35,7 +35,8 @@ search for a given product name, and verify that expected products were returned. This verifies that all parts of your application are correctly wired together. -Create `test/acceptance/product.acceptance.ts` with the following contents: +Create `src/__tests__/acceptance/product.acceptance.ts` with the following +contents: ```ts import {HelloWorldApp} from '../..'; @@ -163,7 +164,7 @@ Run `npm test` and watch the test fail with a helpful error message: ```text TSError: ⨯ Unable to compile TypeScript -test/unit/product-controller.test.ts (13,40): Property 'getDetails' does not exist on type 'ProductController'. (2339) +src/__tests__/unit/product-controller.test.ts (13,40): Property 'getDetails' does not exist on type 'ProductController'. (2339) ``` Now it's time to write the first implementation of the `getDetails` method. @@ -412,8 +413,8 @@ Examine the acceptance test first. A quick review of the source code should tell us what's the problem - the test is relying on `givenEmptyDatabase` and `givenProduct` helpers, but these helpers are not fully implemented yet. Fix that by reusing the helpers from the integration test: Move the helpers to -`test/helpers/database.helpers.ts` and update both the acceptance and the -integration tests to import the helpers from there. +`src/__tests__/helpers/database.helpers.ts` and update both the acceptance and +the integration tests to import the helpers from there. To find out why the API smoke test is failing, you can start the application via `node .` and request the tested endpoint for example using `curl`. You will see diff --git a/docs/site/Testing-Your-Extensions.md b/docs/site/Testing-Your-Extensions.md index 76ad54ce5c52..20c3882b0d6d 100644 --- a/docs/site/Testing-Your-Extensions.md +++ b/docs/site/Testing-Your-Extensions.md @@ -84,7 +84,7 @@ export class PingController { } ``` -{% include code-caption.html content="test/unit/controllers/ping.controller.unit.ts" %} +{% include code-caption.html content="src/__tests__/unit/controllers/ping.controller.unit.ts" %} ```ts import {PingController} from '../../..'; @@ -145,7 +145,7 @@ export function getTestMetadata( } ``` -{% include code-caption.html content="test/unit/decorators/test.decorator.unit.ts" %} +{% include code-caption.html content="src/__tests__/unit/decorators/test.decorator.unit.ts" %} ```ts import {test, getTestMetadata} from '../../..'; @@ -194,7 +194,7 @@ export class RandomNumberProvider implements Provider { } ``` -{% include code-caption.html content="test/unit/providers/random-number.provider.unit.ts" %} +{% include code-caption.html content="src/__tests__/unit/providers/random-number.provider.unit.ts" %} ```ts import {RandomNumberProvider} from '../../..'; @@ -255,7 +255,7 @@ export function TimeMixin>(superClass: T) { } ``` -{% include code-caption.html content="test/integration/mixins/time.mixin.integration.ts" %} +{% include code-caption.html content="src/__tests__/integration/mixins/time.mixin.integration.ts" %} ```ts import {expect} from '@loopback/testlab'; @@ -302,4 +302,4 @@ Have a look at [loopback4-example-log-extension](https://github.com/strongloop/loopback-next/tree/master/examples/log-extension) to understand the extension artifacts and their usage. An Acceptance test can be seen here: -[test/acceptance/log.extension.acceptance.ts](https://github.com/strongloop/loopback-next/blob/master/examples/log-extension/test/acceptance/log.extension.acceptance.ts). +[src/**tests**/acceptance/log.extension.acceptance.ts](https://github.com/strongloop/loopback-next/blob/master/examples/log-extension/src/__tests__/acceptance/log.extension.acceptance.ts). diff --git a/docs/site/Testing-your-application.md b/docs/site/Testing-your-application.md index d6bae0f58f8f..7027a1236bbc 100644 --- a/docs/site/Testing-your-application.md +++ b/docs/site/Testing-your-application.md @@ -103,7 +103,7 @@ database is not something we want to clean before each test it's handy to use an independent in-memory datasource which is filled appropriately using [test data builders](#use-test-data-builders) before each test run. -{% include code-caption.html content="test/fixtures/datasources/testdb.datasource.ts" %} +{% include code-caption.html content="src/__tests__/fixtures/datasources/testdb.datasource.ts" %} ```ts import {juggler} from '@loopback/repository'; @@ -126,7 +126,7 @@ database in the state that caused the test to fail. To clean the database before each test, set up a `beforeEach` hook to call a helper method; for example: -{% include code-caption.html content="test/helpers/database.helpers.ts" %} +{% include code-caption.html content="src/__tests__/helpers/database.helpers.ts" %} ```ts import {ProductRepository, CategoryRepository} from '../../src/repositories'; @@ -141,7 +141,7 @@ export async function givenEmptyDatabase() { In case a repository includes a relation to another repository, ie. Product belongs to Category, include it in the repository call, for example: -{% include code-caption.html content="test/helpers/database.helpers.ts" %} +{% include code-caption.html content="src/__tests__/helpers/database.helpers.ts" %} ```ts import {Getter} from '@loopback/context'; @@ -160,7 +160,7 @@ export async function givenEmptyDatabase() { } ``` -{% include code-caption.html content="test/integration/controllers/product.controller.integration.ts" %} +{% include code-caption.html content="src/__tests__/integration/controllers/product.controller.integration.ts" %} ```ts // in your test file @@ -198,7 +198,7 @@ documents. In practice, a simple function that adds missing required properties is sufficient. -{% include code-caption.html content="test/helpers/database.helpers.ts" %} +{% include code-caption.html content="src/__tests__/helpers/database.helpers.ts" %} ```ts // ... @@ -432,7 +432,7 @@ implementation of its repository dependency using the `testlab` [Create a stub repository](#create-a-stub-repository) for a detailed explanation. -{% include code-caption.html content="test/unit/controllers/product.controller.unit.ts" %} +{% include code-caption.html content="src/__tests__/unit/controllers/product.controller.unit.ts" %} ```ts import { @@ -482,7 +482,7 @@ unit tests to verify the implementation of this additional method. Remember to use [Test data builders](#use-test-data-builders) whenever you need valid data to create a new model instance. -{% include code-caption.html content="test/unit/models/person.model.unit.ts" %} +{% include code-caption.html content="src/__tests__/unit/models/person.model.unit.ts" %} ```ts import {Person} from '../../../src/models'; @@ -569,7 +569,7 @@ Integration tests are one of the places to put the best practices in Here is an example showing how to write an integration test for a custom repository method `findByName`: -{% include code-caption.html content="test/integration/repositories/category.repository.integration.ts" %} +{% include code-caption.html content="src/__tests__/integration/repositories/category.repository.integration.ts" %} ```ts import { @@ -604,7 +604,7 @@ commands and queries produce expected results when executed on a real database. These tests are similar to repository tests with controllers added as another ingredient. -{% include code-caption.html content="test/integration/controllers/product.controller.integration.ts" %} +{% include code-caption.html content="src/__tests__/integration/controllers/product.controller.integration.ts" %} ```ts import {expect} from '@loopback/testlab'; @@ -742,10 +742,9 @@ provides a helper method `validateApiSpec` that builds on top of the popular Example usage: -{% include code-caption.html content= "test/acceptance/api-spec.acceptance.ts" %} +{% include code-caption.html content= "src/__tests__/acceptance/api-spec.acceptance.ts" %} ```ts -// test/acceptance/api-spec.test.ts import {HelloWorldApplication} from '../..'; import {RestServer} from '@loopback/rest'; import {validateApiSpec} from '@loopback/testlab'; @@ -785,7 +784,7 @@ developers consuming your API will find them useful too. Here is an example showing how to run Dredd to test your API against the spec: -{% include code-caption.html content= "test/acceptance/api-spec.acceptance.ts" %} +{% include code-caption.html content= "src/__tests__/acceptance/api-spec.acceptance.ts" %} ```ts import {expect} from '@loopback/testlab'; @@ -857,7 +856,7 @@ two tests (one test for each user role). Here is an example of an acceptance test: -{% include code-caption.html content= "test/acceptance/product.acceptance.ts" %} +{% include code-caption.html content= "src/__tests__/acceptance/product.acceptance.ts" %} ```ts import {HelloWorldApplication} from '../..'; diff --git a/docs/site/todo-tutorial-scaffolding.md b/docs/site/todo-tutorial-scaffolding.md index 3f8a904d0396..13c053537c8d 100644 --- a/docs/site/todo-tutorial-scaffolding.md +++ b/docs/site/todo-tutorial-scaffolding.md @@ -44,6 +44,12 @@ the following: ```text src/ + __tests__/ + README.md + mocha.opts + acceptance/ + home-page.controller.acceptance.ts + ping.controller.acceptance.ts controllers/ home-page.controller.ts README.md @@ -57,12 +63,6 @@ src/ application.ts index.ts sequence.ts -test/ - README.md - mocha.opts - acceptance/ - home-page.controller.acceptance.ts - ping.controller.acceptance.ts node_modules/ *** LICENSE @@ -75,27 +75,27 @@ tslint.build.json tslint.json ``` -| File | Purpose | -| --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| index.ts | Allows importing contents of the `src` folder (for use elsewhere) | -| index.js | Top-level file connecting components of the application. | -| package.json | Your application's package manifest. See [package.json](https://docs.npmjs.com/files/package.json) for details. | -| tsconfig.json | The TypeScript project configuration. See [tsconfig.json](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) for details. | -| tslint.json | [TSLint configuration](https://palantir.github.io/tslint/usage/tslint-json/) | -| tslint.build.json | [TSLint configuration (build only)](https://palantir.github.io/tslint/usage/tslint-json/) | -| README.md | The Markdown-based README generated for your application. | -| LICENSE | A copy of the MIT license. If you do not wish to use this license, please delete this file. | -| src/application.ts | The application class, which extends [`RestApplication`](http://apidocs.strongloop.com/@loopback%2fdocs/rest.html#RestApplication) by default. This is the root of your application, and is where your application will be configured. It also extends [`RepositoryMixin`](https://apidocs.strongloop.com/@loopback%2fdocs/repository.html#RepositoryMixin) which defines the datasource. | -| src/index.ts | The starting point of your microservice. This file creates an instance of your application, runs the booter, then attempts to start the [`RestServer`](http://apidocs.strongloop.com/@loopback%2fdocs/rest.html#RestServer) instance bound to the application. | -| src/sequence.ts | An extension of the [Sequence](Sequence.md) class used to define the set of actions to take during a REST request/response. | -| src/controllers/README.md | Provides information about the controller directory, how to generate new controllers, and where to find more information. | -| src/controllers/ping.controller.ts | A basic controller that responds to GET requests at `/ping`. | -| src/datasources/README.md | Provides information about the datasources directory, how to generate new datasources, and where to find more information. | -| src/models/README.md | Provides information about the models directory, how to generate new models, and where to find more information. | -| src/repositories/README.md | Provides information about the repositories directory, how to generate new repositories, and where to find more information. | -| test/README.md | Please place your tests in this folder. | -| test/mocha.opts | [Mocha](https://mochajs.org/) configuration for running your application's tests. | -| test/acceptance/ping.controller.acceptance.ts | An example test to go with the ping controller in `src/controllers`. | +| File | Purpose | +| ---------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `index.ts` | Allows importing contents of the `src` folder (for use elsewhere) | +| `index.js` | Top-level file connecting components of the application. | +| `package.json` | Your application's package manifest. See [package.json](https://docs.npmjs.com/files/package.json) for details. | +| `tsconfig.json` | The TypeScript project configuration. See [tsconfig.json](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) for details. | +| `tslint.json` | [TSLint configuration](https://palantir.github.io/tslint/usage/tslint-json/) | +| `tslint.build.json` | [TSLint configuration (build only)](https://palantir.github.io/tslint/usage/tslint-json/) | +| `README.md` | The Markdown-based README generated for your application. | +| `LICENSE` | A copy of the MIT license. If you do not wish to use this license, please delete this file. | +| `src/application.ts` | The application class, which extends [`RestApplication`](http://apidocs.strongloop.com/@loopback%2fdocs/rest.html#RestApplication) by default. This is the root of your application, and is where your application will be configured. It also extends [`RepositoryMixin`](https://apidocs.strongloop.com/@loopback%2fdocs/repository.html#RepositoryMixin) which defines the datasource. | +| `src/index.ts` | The starting point of your microservice. This file creates an instance of your application, runs the booter, then attempts to start the [`RestServer`](http://apidocs.strongloop.com/@loopback%2fdocs/rest.html#RestServer) instance bound to the application. | +| `src/sequence.ts | An extension of the [Sequence](Sequence.md) class used to define the set of actions to take during a REST request/response. | +| `src/controllers/README.md` | Provides information about the controller directory, how to generate new controllers, and where to find more information. | +| `src/controllers/ping.controller.ts` | A basic controller that responds to GET requests at `/ping`. | +| `src/datasources/README.md` | Provides information about the datasources directory, how to generate new datasources, and where to find more information. | +| `src/models/README.md` | Provides information about the models directory, how to generate new models, and where to find more information. | +| `src/repositories/README.md` | Provides information about the repositories directory, how to generate new repositories, and where to find more information. | +| `src/__tests__/README.md` | Please place your tests in this folder. | +| `src/test/mocha.opts` | [Mocha](https://mochajs.org/) configuration for running your application's tests. | +| `src/__tests__/acceptance/ping.controller.acceptance.ts` | An example test to go with the ping controller in `src/controllers`. | ### Navigation diff --git a/examples/todo-list/package.json b/examples/todo-list/package.json index 6e555f3b491a..b30c29269343 100644 --- a/examples/todo-list/package.json +++ b/examples/todo-list/package.json @@ -22,7 +22,7 @@ "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", + "migrate": "node ./dist/migrate", "prestart": "npm run build", "start": "node ." }, diff --git a/examples/todo/package.json b/examples/todo/package.json index 2c6f6177f09f..729df091bb81 100644 --- a/examples/todo/package.json +++ b/examples/todo/package.json @@ -22,7 +22,7 @@ "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", + "migrate": "node ./dist/migrate", "prestart": "npm run build", "start": "node ." }, diff --git a/packages/build/README.md b/packages/build/README.md index 830423e75f87..5b9b97ec0ab9 100644 --- a/packages/build/README.md +++ b/packages/build/README.md @@ -40,7 +40,7 @@ To use `@loopback/build` for your package: "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__\"", "posttest": "npm run lint", "start": "npm run build && node .", "prepublishOnly": "npm run test" diff --git a/packages/build/test/integration/scripts.integration.js b/packages/build/test/integration/scripts.integration.js index c50721aeda73..273eb66f8601 100644 --- a/packages/build/test/integration/scripts.integration.js +++ b/packages/build/test/integration/scripts.integration.js @@ -380,7 +380,7 @@ describe('mocha', function() { it('loads built-in mocha.opts file', () => { var run = require('../../bin/run-mocha'); - var command = run(['node', 'bin/run-mocha', '"dist/test"'], true); + var command = run(['node', 'bin/run-mocha', '"dist/__tests__"'], true); const builtInMochaOptsFile = path.join( __dirname, '../../config/mocha.opts', @@ -394,7 +394,7 @@ describe('mocha', function() { it('honors --opts option', () => { var run = require('../../bin/run-mocha'); var command = run( - ['node', 'bin/run-mocha', '--opts custom/mocha.opts', '"dist/test"'], + ['node', 'bin/run-mocha', '--opts custom/mocha.opts', '"dist/__tests__"'], true, ); assert( @@ -410,7 +410,7 @@ describe('mocha', function() { fs.copyFileSync(buitInMochaOptsPath, destPath); - var command = run(['node', 'bin/run-mocha', '"dist/test"'], true); + var command = run(['node', 'bin/run-mocha', '"dist/__tests__"'], true); assert( command.indexOf('--opts') === -1, 'should skip built-in mocha.opts file when specific project file exist', diff --git a/packages/cli/generators/app/templates/test/README.md b/packages/cli/generators/app/templates/src/__tests__/README.md similarity index 100% rename from packages/cli/generators/app/templates/test/README.md rename to packages/cli/generators/app/templates/src/__tests__/README.md diff --git a/packages/cli/generators/app/templates/test/acceptance/home-page.acceptance.ts.ejs b/packages/cli/generators/app/templates/src/__tests__/acceptance/home-page.acceptance.ts.ejs similarity index 100% rename from packages/cli/generators/app/templates/test/acceptance/home-page.acceptance.ts.ejs rename to packages/cli/generators/app/templates/src/__tests__/acceptance/home-page.acceptance.ts.ejs diff --git a/packages/cli/generators/app/templates/test/acceptance/ping.controller.acceptance.ts.ejs b/packages/cli/generators/app/templates/src/__tests__/acceptance/ping.controller.acceptance.ts.ejs similarity index 100% rename from packages/cli/generators/app/templates/test/acceptance/ping.controller.acceptance.ts.ejs rename to packages/cli/generators/app/templates/src/__tests__/acceptance/ping.controller.acceptance.ts.ejs diff --git a/packages/cli/generators/app/templates/test/acceptance/test-helper.ts.ejs b/packages/cli/generators/app/templates/src/__tests__/acceptance/test-helper.ts.ejs similarity index 100% rename from packages/cli/generators/app/templates/test/acceptance/test-helper.ts.ejs rename to packages/cli/generators/app/templates/src/__tests__/acceptance/test-helper.ts.ejs diff --git a/packages/cli/generators/app/templates/src/application.ts.ejs b/packages/cli/generators/app/templates/src/application.ts.ejs index d5f4d6c4dc85..875bc2450b33 100644 --- a/packages/cli/generators/app/templates/src/application.ts.ejs +++ b/packages/cli/generators/app/templates/src/application.ts.ejs @@ -30,7 +30,7 @@ export class <%= project.applicationName %> extends BootMixin(RestApplication) { this.sequence(MySequence); // Set up default home page - this.static('/', path.join(__dirname, '../../public')); + this.static('/', path.join(__dirname, '../public')); // Customize @loopback/rest-explorer configuration here this.bind(RestExplorerBindings.CONFIG).to({ diff --git a/packages/cli/generators/extension/templates/test/acceptance/README.md b/packages/cli/generators/extension/templates/src/__tests__/acceptance/README.md similarity index 100% rename from packages/cli/generators/extension/templates/test/acceptance/README.md rename to packages/cli/generators/extension/templates/src/__tests__/acceptance/README.md diff --git a/packages/cli/generators/extension/templates/test/integration/README.md b/packages/cli/generators/extension/templates/src/__tests__/integration/README.md similarity index 100% rename from packages/cli/generators/extension/templates/test/integration/README.md rename to packages/cli/generators/extension/templates/src/__tests__/integration/README.md diff --git a/packages/cli/generators/extension/templates/test/unit/README.md b/packages/cli/generators/extension/templates/src/__tests__/unit/README.md similarity index 100% rename from packages/cli/generators/extension/templates/test/unit/README.md rename to packages/cli/generators/extension/templates/src/__tests__/unit/README.md diff --git a/packages/cli/generators/project/templates/package.json.ejs b/packages/cli/generators/project/templates/package.json.ejs index c30c45f0320a..6246cdfa227b 100644 --- a/packages/cli/generators/project/templates/package.json.ejs +++ b/packages/cli/generators/project/templates/package.json.ejs @@ -36,18 +36,18 @@ <% } -%> "pretest": "npm run clean && npm run build", <% if (project.mocha) { -%> - "test": "lb-mocha --allow-console-logs \"dist/test\"", + "test": "lb-mocha --allow-console-logs \"dist/__tests__\"", <% } -%> <% if (project.prettier || project.tslint) { -%> "posttest": "npm run lint", <% } -%> <% if (project.mocha && (project.prettier || project.tslint)) { -%> - "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", <% } else if (project.mocha) { -%> - "test:dev": "lb-mocha --allow-console-logs dist/test/**/*.js", + "test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js", <% } -%> <% if (project.projectType === 'application') { -%> - "migrate": "node ./dist/src/migrate", + "migrate": "node ./dist/migrate", "prestart": "npm run build", "start": "node .", <% } -%> @@ -65,9 +65,9 @@ "README.md", "index.js", "index.d.ts", - "dist/src", - "dist/index*", - "src" + "dist", + "src", + "!*/__tests__" ], "dependencies": { "@loopback/boot": "<%= project.dependencies['@loopback/boot'] -%>", diff --git a/packages/cli/generators/project/templates/package.plain.json.ejs b/packages/cli/generators/project/templates/package.plain.json.ejs index 36c39c05c9c3..ac1298e2c774 100644 --- a/packages/cli/generators/project/templates/package.plain.json.ejs +++ b/packages/cli/generators/project/templates/package.plain.json.ejs @@ -35,18 +35,18 @@ <% } -%> "pretest": "npm run clean && npm run build", <% if (project.mocha) { -%> - "test": "mocha dist/test", + "test": "mocha dist/__tests__", <% } -%> <% if (project.prettier || project.tslint) { -%> "posttest": "npm run lint", <% } -%> <% if (project.mocha && (project.prettier || project.tslint)) { -%> - "test:dev": "mocha dist/test/**/*.js && npm run posttest", + "test:dev": "mocha dist/__tests__/**/*.js && npm run posttest", <% } else if (project.mocha) { -%> - "test:dev": "mocha dist/test/**/*.js", + "test:dev": "mocha dist/__tests__/**/*.js", <% } -%> <% if (project.projectType === 'application') { -%> - "migrate": "node ./dist/src/migrate", + "migrate": "node ./dist/migrate", "start": "npm run build && node .", <% } -%> "prepare": "npm run build" @@ -64,7 +64,8 @@ "index.js", "index.d.ts", "dist", - "src" + "src", + "!*/__tests__" ], "dependencies": { "@loopback/boot": "<%= project.dependencies['@loopback/boot'] -%>", diff --git a/packages/cli/generators/project/templates/tsconfig.json.ejs b/packages/cli/generators/project/templates/tsconfig.json.ejs index 3558f3da80cf..e89fc7f68e4f 100644 --- a/packages/cli/generators/project/templates/tsconfig.json.ejs +++ b/packages/cli/generators/project/templates/tsconfig.json.ejs @@ -2,8 +2,14 @@ "$schema": "http://json.schemastore.org/tsconfig", <% if (project.loopbackBuild) { -%> "extends": "@loopback/build/config/tsconfig.common.json", + "compilerOptions": { + "rootDir": "src" + }, + "include": ["src"] <% } else { -%> "compilerOptions": { + "rootDir": "src", + "emitDecoratorMetadata": true, "experimentalDecorators": true, "noImplicitAny": true, @@ -17,15 +23,11 @@ "sourceMap": true, "declaration": true }, -<% } -%> - "include": [ - "src", - "test", - "index.ts" - ], + "include": ["src"], "exclude": [ "node_modules/**", "packages/*/node_modules/**", "**/*.d.ts" ] +<% } -%> } diff --git a/packages/cli/test/integration/generators/app.integration.js b/packages/cli/test/integration/generators/app.integration.js index ba47c1165f26..6454afbb9423 100644 --- a/packages/cli/test/integration/generators/app.integration.js +++ b/packages/cli/test/integration/generators/app.integration.js @@ -69,15 +69,15 @@ describe('app-generator specific files', () => { /\'\@loopback\/rest\'/, ); assert.fileContent( - 'test/acceptance/ping.controller.acceptance.ts', + 'src/__tests__/acceptance/ping.controller.acceptance.ts', /describe\('PingController'/, ); assert.fileContent( - 'test/acceptance/home-page.acceptance.ts', + 'src/__tests__/acceptance/home-page.acceptance.ts', /describe\('HomePage'/, ); assert.fileContent( - 'test/acceptance/test-helper.ts', + 'src/__tests__/acceptance/test-helper.ts', /export async function setupApplication/, ); }); @@ -98,7 +98,7 @@ describe('app-generator specific files', () => { it('creates npm script "migrate-db"', async () => { const pkg = JSON.parse(await readFile('package.json')); - expect(pkg.scripts).to.have.property('migrate', 'node ./dist/src/migrate'); + expect(pkg.scripts).to.have.property('migrate', 'node ./dist/migrate'); }); }); diff --git a/packages/cli/test/integration/lib/project-generator.js b/packages/cli/test/integration/lib/project-generator.js index ca399e61de53..8f344845ac1e 100644 --- a/packages/cli/test/integration/lib/project-generator.js +++ b/packages/cli/test/integration/lib/project-generator.js @@ -254,10 +254,7 @@ module.exports = function(projGenerator, props, projectType) { ['tslint.json', '@loopback/tslint-config'], ['tsconfig.json', '@loopback/build'], ]); - assert.noFileContent([ - ['tslint.json', '"rules"'], - ['tsconfig.json', '"compilerOptions"'], - ]); + assert.noFileContent([['tslint.json', '"rules"']]); if (projectType === 'application') { assert.fileContent(