From 066d52510cda94ca5d26a90dd5446ab2173fe110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Thu, 24 Jan 2019 13:23:10 +0100 Subject: [PATCH] build(testlab): move test files to `src/__tests__` This change greatly simplifies our build and project setup. - 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 change is also enabling future improvements, for example TypeScript project references and migration to jest test runner. --- .nycrc | 1 + package.json | 2 +- packages/testlab/package.json | 8 ++++---- packages/testlab/{test => src/__tests__}/fixtures/test.ts | 0 .../__tests__}/integration/test-sandbox.integration.ts | 0 .../__tests__}/integration/testlab.smoke.integration.ts | 0 .../testlab/{test => src/__tests__}/unit/to-json.test.ts | 4 ++-- packages/testlab/tsconfig.build.json | 4 ++-- 8 files changed, 10 insertions(+), 9 deletions(-) rename packages/testlab/{test => src/__tests__}/fixtures/test.ts (100%) rename packages/testlab/{test => src/__tests__}/integration/test-sandbox.integration.ts (100%) rename packages/testlab/{test => src/__tests__}/integration/testlab.smoke.integration.ts (100%) rename packages/testlab/{test => src/__tests__}/unit/to-json.test.ts (97%) diff --git a/.nycrc b/.nycrc index 736832778af9..b63ce22107ba 100644 --- a/.nycrc +++ b/.nycrc @@ -6,6 +6,7 @@ ], "exclude": [ "packages/*/dist/test/", + "packages/*/dist/__tests__/", "packages/cli/test/", "examples/*/dist/test/", "**/.sandbox/" diff --git a/package.json b/package.json index fe89b0e1020d..4c4515be87ab 100644 --- a/package.json +++ b/package.json @@ -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\" \"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/test/**/*.js\" \"packages/cli/test/**/*.js\" \"packages/build/test/*/*.js\"", "posttest": "npm run lint" }, "config": { diff --git a/packages/testlab/package.json b/packages/testlab/package.json index 6356b811499c..32a801591f86 100644 --- a/packages/testlab/package.json +++ b/packages/testlab/package.json @@ -10,7 +10,7 @@ "build:apidocs": "lb-apidocs", "clean": "lb-clean loopback-testlab*.tgz dist package api-docs", "pretest": "npm run build", - "test": "lb-mocha \"dist/test\"", + "test": "lb-mocha \"dist/__tests__\"", "verify": "npm pack && tar xf loopback-testlab*.tgz && tree package && npm run clean" }, "author": "IBM", @@ -39,10 +39,10 @@ "README.md", "index.js", "index.d.ts", - "dist/src", - "dist/index*", + "dist", "should-as-function.d.ts", - "src" + "src", + "!*/__tests__" ], "repository": { "type": "git", diff --git a/packages/testlab/test/fixtures/test.ts b/packages/testlab/src/__tests__/fixtures/test.ts similarity index 100% rename from packages/testlab/test/fixtures/test.ts rename to packages/testlab/src/__tests__/fixtures/test.ts diff --git a/packages/testlab/test/integration/test-sandbox.integration.ts b/packages/testlab/src/__tests__/integration/test-sandbox.integration.ts similarity index 100% rename from packages/testlab/test/integration/test-sandbox.integration.ts rename to packages/testlab/src/__tests__/integration/test-sandbox.integration.ts diff --git a/packages/testlab/test/integration/testlab.smoke.integration.ts b/packages/testlab/src/__tests__/integration/testlab.smoke.integration.ts similarity index 100% rename from packages/testlab/test/integration/testlab.smoke.integration.ts rename to packages/testlab/src/__tests__/integration/testlab.smoke.integration.ts diff --git a/packages/testlab/test/unit/to-json.test.ts b/packages/testlab/src/__tests__/unit/to-json.test.ts similarity index 97% rename from packages/testlab/test/unit/to-json.test.ts rename to packages/testlab/src/__tests__/unit/to-json.test.ts index 726dd0ef6574..6ac0bc8fb028 100644 --- a/packages/testlab/test/unit/to-json.test.ts +++ b/packages/testlab/src/__tests__/unit/to-json.test.ts @@ -3,8 +3,8 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT -import {expect} from '../../src/expect'; -import {toJSON} from '../../src/to-json'; +import {expect} from '../../expect'; +import {toJSON} from '../../to-json'; describe('toJSON', () => { it('removes properties set to undefined', () => { diff --git a/packages/testlab/tsconfig.build.json b/packages/testlab/tsconfig.build.json index f8bd0f50ef8f..6e15e4be4f6f 100644 --- a/packages/testlab/tsconfig.build.json +++ b/packages/testlab/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"] }