From 24e4cfe8c5fdf497cad6157cb88277239a4a9b50 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 2 Apr 2020 10:03:07 -0700 Subject: [PATCH 1/5] feat(build): upgrade to mocha 8.x that supports parallel testing BREAKING CHANGE: We have upgraded to `mocha@8.0.1` and removed support for `--opts` and `test/mocha.opts`. It may break your application if it depends on earlier version of `@loopback/build` for `npm test`. See a list of breaking changes of mocha 8.x at: https://github.com/mochajs/mocha/releases/tag/v8.0.0 --- .vscode/launch.json | 2 ++ packages/build/bin/run-mocha.js | 1 - packages/build/bin/utils.js | 1 - packages/build/config/.mocharc.json | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 9e7fd55cf293..af2aaa5af443 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,7 @@ "program": "${workspaceRoot}/packages/build/node_modules/mocha/bin/_mocha", "runtimeArgs": ["-r", "${workspaceRoot}/packages/build/node_modules/source-map-support/register"], "cwd": "${workspaceRoot}", + "autoAttachChildProcesses": true, "args": [ "--config", "${workspaceRoot}/packages/build/config/.mocharc.json", @@ -26,6 +27,7 @@ "program": "${workspaceRoot}/bin/mocha-current-file", "runtimeArgs": ["-r", "${workspaceRoot}/packages/build/node_modules/source-map-support/register"], "cwd": "${workspaceRoot}", + "autoAttachChildProcesses": true, "args": [ "--config", "${workspaceRoot}/packages/build/config/.mocharc.json", diff --git a/packages/build/bin/run-mocha.js b/packages/build/bin/run-mocha.js index cc988314f905..0670f3835794 100755 --- a/packages/build/bin/run-mocha.js +++ b/packages/build/bin/run-mocha.js @@ -24,7 +24,6 @@ function run(argv, options) { !utils.isOptionSet( mochaOpts, '--config', // mocha 6.x - '--opts', // legacy '--package', // mocha 6.x '--no-config', // mocha 6.x ) && !utils.mochaConfiguredForProject(); diff --git a/packages/build/bin/utils.js b/packages/build/bin/utils.js index dd39a93aabd2..14d81ea3699c 100644 --- a/packages/build/bin/utils.js +++ b/packages/build/bin/utils.js @@ -228,7 +228,6 @@ function mochaConfiguredForProject() { '.mocharc.json', '.mocharc.yaml', '.mocharc.yml', - 'test/mocha.opts', ]; return configFiles.some(f => { const configFile = path.join(getPackageDir(), f); diff --git a/packages/build/config/.mocharc.json b/packages/build/config/.mocharc.json index 1be483a88471..f310739c9b10 100644 --- a/packages/build/config/.mocharc.json +++ b/packages/build/config/.mocharc.json @@ -1,5 +1,5 @@ { - "require": "source-map-support/register", + "require": ["source-map-support/register"], "recursive": true, "exit": true, "reporter": "dot" From 9983065923658795be31ac580887156e700eb39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 12 Jun 2020 10:20:00 +0200 Subject: [PATCH 2/5] test: enable parallel test execution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5b974d63e289..54cfc0a43e3a 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "build:site": "./bin/build-docs-site.sh", "docs:prepare": "./docs/bin/build-preview-site.sh", "docs:start": "cd docs/_preview && bundle exec jekyll serve --no-w --i", - "mocha": "node packages/build/bin/run-mocha --lang en_US.UTF-8 --timeout 5000 \"packages/*/dist/__tests__/**/*.js\" \"extensions/*/dist/__tests__/**/*.js\" \"examples/*/dist/__tests__/**/*.js\" \"packages/cli/test/**/*.js\" \"packages/build/test/*/*.js\"", + "mocha": "node packages/build/bin/run-mocha --lang en_US.UTF-8 --timeout 15000 --parallel \"packages/*/dist/__tests__/**/*.js\" \"extensions/*/dist/__tests__/**/*.js\" \"examples/*/dist/__tests__/**/*.js\" \"packages/cli/test/**/*.js\" \"packages/build/test/*/*.js\"", "posttest": "npm run lint" }, "config": { From cee8b18356d9077e89a55ca3d755350899d28549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 12 Jun 2020 10:19:10 +0200 Subject: [PATCH 3/5] test(cli): rework snapshots to support parallel test execution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- .../test/integration/cli/cli.integration.js | 2 +- .../integration/generators/app.integration.js | 2 +- .../generators/controller.integration.js | 2 +- .../generators/datasource.integration.js | 2 +- .../generators/discover.integration.js | 2 +- .../import-lb3-models.integration.js | 2 +- .../generators/interceptor.integration.js | 2 +- .../generators/model.integration.js | 2 +- .../generators/openapi-client.integration.js | 2 +- .../openapi-petstore.integration.js | 2 +- ...penapi-uspto-with-anonymous.integration.js | 2 +- .../generators/openapi-uspto.integration.js | 2 +- .../relation.belongs-to.integration.js | 2 +- .../relation.has-many.integration.js | 2 +- .../relation.has-one.integration.js | 2 +- .../generators/remote-service.integration.js | 2 +- .../generators/rest-crud.integration.js | 2 +- .../swagger-petstore.integration.js | 2 +- packages/cli/test/snapshot-matcher.js | 17 ++++ packages/cli/test/snapshots.js | 79 ++++++++++++------- .../test/unit/openapi/controller-spec.unit.js | 2 +- .../test/unit/openapi/schema-model.unit.js | 2 +- 22 files changed, 86 insertions(+), 50 deletions(-) diff --git a/packages/cli/test/integration/cli/cli.integration.js b/packages/cli/test/integration/cli/cli.integration.js index 7432a1c68615..c835870408ec 100644 --- a/packages/cli/test/integration/cli/cli.integration.js +++ b/packages/cli/test/integration/cli/cli.integration.js @@ -12,7 +12,7 @@ const main = require('../../../lib/cli'); const { expectToMatchSnapshot, expectFileToMatchSnapshot, -} = require('../../snapshots'); +} = require('../../snapshots')(); function getLog(buffer) { buffer = buffer || []; diff --git a/packages/cli/test/integration/generators/app.integration.js b/packages/cli/test/integration/generators/app.integration.js index 66fadf6db456..6a72d81e05b2 100644 --- a/packages/cli/test/integration/generators/app.integration.js +++ b/packages/cli/test/integration/generators/app.integration.js @@ -21,7 +21,7 @@ const props = { }; const {expect} = require('@loopback/testlab'); -const {assertFilesToMatchSnapshot} = require('../../snapshots'); +const {assertFilesToMatchSnapshot} = require('../../snapshots')(); const tests = require('../lib/project-generator')( generator, diff --git a/packages/cli/test/integration/generators/controller.integration.js b/packages/cli/test/integration/generators/controller.integration.js index 685c3016ab94..dd20f1d04158 100644 --- a/packages/cli/test/integration/generators/controller.integration.js +++ b/packages/cli/test/integration/generators/controller.integration.js @@ -18,7 +18,7 @@ const tests = require('../lib/artifact-generator')(generator); const baseTests = require('../lib/base-generator')(generator); const testUtils = require('../../test-utils'); -const {expectFileToMatchSnapshot} = require('../../snapshots'); +const {expectFileToMatchSnapshot} = require('../../snapshots')(); // Test Sandbox const sandbox = new TestSandbox(path.resolve(__dirname, '../.sandbox')); diff --git a/packages/cli/test/integration/generators/datasource.integration.js b/packages/cli/test/integration/generators/datasource.integration.js index ea5f2bae59f6..e7ac952797da 100644 --- a/packages/cli/test/integration/generators/datasource.integration.js +++ b/packages/cli/test/integration/generators/datasource.integration.js @@ -17,7 +17,7 @@ const generator = path.join(__dirname, '../../../generators/datasource'); const tests = require('../lib/artifact-generator')(generator); const baseTests = require('../lib/base-generator')(generator); const testUtils = require('../../test-utils'); -const {expectFileToMatchSnapshot} = require('../../snapshots'); +const {expectFileToMatchSnapshot} = require('../../snapshots')(); // Test Sandbox const sandbox = new TestSandbox(path.resolve(__dirname, '../.sandbox')); diff --git a/packages/cli/test/integration/generators/discover.integration.js b/packages/cli/test/integration/generators/discover.integration.js index e510ea7af586..8b313cfeecb8 100644 --- a/packages/cli/test/integration/generators/discover.integration.js +++ b/packages/cli/test/integration/generators/discover.integration.js @@ -9,7 +9,7 @@ const path = require('path'); const assert = require('yeoman-assert'); const {expect, TestSandbox} = require('@loopback/testlab'); -const {expectFileToMatchSnapshot} = require('../../snapshots'); +const {expectFileToMatchSnapshot} = require('../../snapshots')(); const generator = path.join(__dirname, '../../../generators/discover'); require('../lib/artifact-generator')(generator); diff --git a/packages/cli/test/integration/generators/import-lb3-models.integration.js b/packages/cli/test/integration/generators/import-lb3-models.integration.js index 999ac3fe5dcc..60ea55799e97 100644 --- a/packages/cli/test/integration/generators/import-lb3-models.integration.js +++ b/packages/cli/test/integration/generators/import-lb3-models.integration.js @@ -9,7 +9,7 @@ const assert = require('yeoman-assert'); const {expect, TestSandbox} = require('@loopback/testlab'); const path = require('path'); const generator = path.join(__dirname, '../../../generators/import-lb3-models'); -const {expectFileToMatchSnapshot} = require('../../snapshots'); +const {expectFileToMatchSnapshot} = require('../../snapshots')(); const testUtils = require('../../test-utils'); const sandbox = new TestSandbox(path.resolve(__dirname, '../.sandbox')); diff --git a/packages/cli/test/integration/generators/interceptor.integration.js b/packages/cli/test/integration/generators/interceptor.integration.js index 5d4e0e2fa2cf..80427448055a 100644 --- a/packages/cli/test/integration/generators/interceptor.integration.js +++ b/packages/cli/test/integration/generators/interceptor.integration.js @@ -12,7 +12,7 @@ const generator = path.join(__dirname, '../../../generators/interceptor'); const SANDBOX_FILES = require('../../fixtures/interceptor').SANDBOX_FILES; const testUtils = require('../../test-utils'); -const {expectFileToMatchSnapshot} = require('../../snapshots'); +const {expectFileToMatchSnapshot} = require('../../snapshots')(); // Test Sandbox const sandbox = new TestSandbox(path.resolve(__dirname, '../.sandbox')); diff --git a/packages/cli/test/integration/generators/model.integration.js b/packages/cli/test/integration/generators/model.integration.js index ce3c8e234ddf..feb851022b3d 100644 --- a/packages/cli/test/integration/generators/model.integration.js +++ b/packages/cli/test/integration/generators/model.integration.js @@ -9,7 +9,7 @@ const path = require('path'); const assert = require('yeoman-assert'); const {expect, TestSandbox} = require('@loopback/testlab'); -const {expectFileToMatchSnapshot} = require('../../snapshots'); +const {expectFileToMatchSnapshot} = require('../../snapshots')(); const {remove} = require('fs-extra'); const generator = path.join(__dirname, '../../../generators/model'); diff --git a/packages/cli/test/integration/generators/openapi-client.integration.js b/packages/cli/test/integration/generators/openapi-client.integration.js index 2bd175b06c9f..b5bc8e8a749f 100644 --- a/packages/cli/test/integration/generators/openapi-client.integration.js +++ b/packages/cli/test/integration/generators/openapi-client.integration.js @@ -7,7 +7,7 @@ const path = require('path'); const {TestSandbox} = require('@loopback/testlab'); -const {assertFilesToMatchSnapshot} = require('../../snapshots'); +const {assertFilesToMatchSnapshot} = require('../../snapshots')(); const generator = path.join(__dirname, '../../../generators/openapi'); const specPath = path.resolve( diff --git a/packages/cli/test/integration/generators/openapi-petstore.integration.js b/packages/cli/test/integration/generators/openapi-petstore.integration.js index 013324a8ee96..16545a290cfb 100644 --- a/packages/cli/test/integration/generators/openapi-petstore.integration.js +++ b/packages/cli/test/integration/generators/openapi-petstore.integration.js @@ -7,7 +7,7 @@ const path = require('path'); const {TestSandbox} = require('@loopback/testlab'); -const {assertFilesToMatchSnapshot} = require('../../snapshots'); +const {assertFilesToMatchSnapshot} = require('../../snapshots')(); const generator = path.join(__dirname, '../../../generators/openapi'); const specPath = path.join( diff --git a/packages/cli/test/integration/generators/openapi-uspto-with-anonymous.integration.js b/packages/cli/test/integration/generators/openapi-uspto-with-anonymous.integration.js index 8a55fe764ea6..8cdb06971c24 100644 --- a/packages/cli/test/integration/generators/openapi-uspto-with-anonymous.integration.js +++ b/packages/cli/test/integration/generators/openapi-uspto-with-anonymous.integration.js @@ -7,7 +7,7 @@ const path = require('path'); const {TestSandbox} = require('@loopback/testlab'); -const {assertFilesToMatchSnapshot} = require('../../snapshots'); +const {assertFilesToMatchSnapshot} = require('../../snapshots')(); const generator = path.join(__dirname, '../../../generators/openapi'); const specPath = path.join(__dirname, '../../fixtures/openapi/3.0/uspto.yaml'); diff --git a/packages/cli/test/integration/generators/openapi-uspto.integration.js b/packages/cli/test/integration/generators/openapi-uspto.integration.js index b456a31de6e6..f1d3abe206b3 100644 --- a/packages/cli/test/integration/generators/openapi-uspto.integration.js +++ b/packages/cli/test/integration/generators/openapi-uspto.integration.js @@ -7,7 +7,7 @@ const path = require('path'); const {TestSandbox} = require('@loopback/testlab'); -const {assertFilesToMatchSnapshot} = require('../../snapshots'); +const {assertFilesToMatchSnapshot} = require('../../snapshots')(); const generator = path.join(__dirname, '../../../generators/openapi'); const specPath = path.join(__dirname, '../../fixtures/openapi/3.0/uspto.yaml'); diff --git a/packages/cli/test/integration/generators/relation.belongs-to.integration.js b/packages/cli/test/integration/generators/relation.belongs-to.integration.js index 1343457a84fe..1cbf363c25d5 100644 --- a/packages/cli/test/integration/generators/relation.belongs-to.integration.js +++ b/packages/cli/test/integration/generators/relation.belongs-to.integration.js @@ -8,7 +8,7 @@ const path = require('path'); const assert = require('yeoman-assert'); const {expect, TestSandbox} = require('@loopback/testlab'); -const {expectFileToMatchSnapshot} = require('../../snapshots'); +const {expectFileToMatchSnapshot} = require('../../snapshots')(); const generator = path.join(__dirname, '../../../generators/relation'); const {SANDBOX_FILES, SourceEntries} = require('../../fixtures/relation'); diff --git a/packages/cli/test/integration/generators/relation.has-many.integration.js b/packages/cli/test/integration/generators/relation.has-many.integration.js index 92dc2c6a2409..cedf57b36b3d 100644 --- a/packages/cli/test/integration/generators/relation.has-many.integration.js +++ b/packages/cli/test/integration/generators/relation.has-many.integration.js @@ -8,7 +8,7 @@ const path = require('path'); const assert = require('yeoman-assert'); const {expect, TestSandbox} = require('@loopback/testlab'); -const {expectFileToMatchSnapshot} = require('../../snapshots'); +const {expectFileToMatchSnapshot} = require('../../snapshots')(); const generator = path.join(__dirname, '../../../generators/relation'); const {SANDBOX_FILES, SourceEntries} = require('../../fixtures/relation'); diff --git a/packages/cli/test/integration/generators/relation.has-one.integration.js b/packages/cli/test/integration/generators/relation.has-one.integration.js index 534182a75e56..f782463e8567 100644 --- a/packages/cli/test/integration/generators/relation.has-one.integration.js +++ b/packages/cli/test/integration/generators/relation.has-one.integration.js @@ -8,7 +8,7 @@ const path = require('path'); const assert = require('yeoman-assert'); const {expect, TestSandbox} = require('@loopback/testlab'); -const {expectFileToMatchSnapshot} = require('../../snapshots'); +const {expectFileToMatchSnapshot} = require('../../snapshots')(); const generator = path.join(__dirname, '../../../generators/relation'); const {SANDBOX_FILES, SourceEntries} = require('../../fixtures/relation'); diff --git a/packages/cli/test/integration/generators/remote-service.integration.js b/packages/cli/test/integration/generators/remote-service.integration.js index 0aa3085542ad..eb2f5eb6a977 100644 --- a/packages/cli/test/integration/generators/remote-service.integration.js +++ b/packages/cli/test/integration/generators/remote-service.integration.js @@ -15,7 +15,7 @@ const TestSandbox = testlab.TestSandbox; const generator = path.join(__dirname, '../../../generators/service'); const SANDBOX_FILES = require('../../fixtures/service').SANDBOX_FILES; const testUtils = require('../../test-utils'); -const {expectFileToMatchSnapshot} = require('../../snapshots'); +const {expectFileToMatchSnapshot} = require('../../snapshots')(); // Test Sandbox const sandbox = new TestSandbox(path.resolve(__dirname, '../.sandbox')); diff --git a/packages/cli/test/integration/generators/rest-crud.integration.js b/packages/cli/test/integration/generators/rest-crud.integration.js index 96b444669970..ee0498f080a1 100644 --- a/packages/cli/test/integration/generators/rest-crud.integration.js +++ b/packages/cli/test/integration/generators/rest-crud.integration.js @@ -15,7 +15,7 @@ const TestSandbox = testlab.TestSandbox; const generator = path.join(__dirname, '../../../generators/rest-crud'); const SANDBOX_FILES = require('../../fixtures/rest-crud').SANDBOX_FILES; const testUtils = require('../../test-utils'); -const {expectFileToMatchSnapshot} = require('../../snapshots'); +const {expectFileToMatchSnapshot} = require('../../snapshots')(); // Test Sandbox const sandbox = new TestSandbox(path.resolve(__dirname, '../.sandbox')); diff --git a/packages/cli/test/integration/generators/swagger-petstore.integration.js b/packages/cli/test/integration/generators/swagger-petstore.integration.js index f02db2990232..483cb34de3aa 100644 --- a/packages/cli/test/integration/generators/swagger-petstore.integration.js +++ b/packages/cli/test/integration/generators/swagger-petstore.integration.js @@ -12,7 +12,7 @@ const specPath = path.join( __dirname, '../../fixtures/openapi/2.0/petstore-expanded-swagger.json', ); -const {expectFileToMatchSnapshot} = require('../../snapshots'); +const {expectFileToMatchSnapshot} = require('../../snapshots')(); const testlab = require('@loopback/testlab'); const TestSandbox = testlab.TestSandbox; diff --git a/packages/cli/test/snapshot-matcher.js b/packages/cli/test/snapshot-matcher.js index 17b841d3f6a5..4b352f7a541f 100644 --- a/packages/cli/test/snapshot-matcher.js +++ b/packages/cli/test/snapshot-matcher.js @@ -17,6 +17,7 @@ move this file to a standalone package so that all Mocha users can use it. const chalk = require('chalk'); const assert = require('assert'); const path = require('path'); +const debug = require('debug')('test:snapshot-matcher'); module.exports = { initializeSnapshots, @@ -43,6 +44,22 @@ module.exports = { * ``` */ function initializeSnapshots(snapshotDir) { + if (debug.enabled) { + const stack = new Error().stack + .split(/\n/g) + // Remove the error message and the top stack frame pointing to ourselves + // and pick three frames (max), that should be enough to identify + // which test file called us. + .slice(2, 5) + .map(f => `\n${f}`) + .join(); + debug( + 'Initializing snapshot matcher, storing snapshots in %s%s', + snapshotDir, + stack, + ); + } + let currentTest; let snapshotErrors = false; diff --git a/packages/cli/test/snapshots.js b/packages/cli/test/snapshots.js index 4e787ed8fe25..5e51d79b17a7 100644 --- a/packages/cli/test/snapshots.js +++ b/packages/cli/test/snapshots.js @@ -10,41 +10,60 @@ const fs = require('fs'); const path = require('path'); const {initializeSnapshots} = require('./snapshot-matcher'); -const expectToMatchSnapshot = initializeSnapshots( - path.resolve(__dirname, '../snapshots'), -); - -function expectFileToMatchSnapshot(filePath) { - assert.file(filePath); - const content = fs.readFileSync(filePath, {encoding: 'utf-8'}); - expectToMatchSnapshot(content); -} +module.exports = install; /** - * Assert a list of files to match snapshots - * @param {object} options Options - * - exists: assert the file exists or not - * - rootPath: rootPath for file names - * @param {...string} files + * Initialize snapshot engine and install before/after hooks. + * + * It's important to call this method from each test file to ensure hooks are + * installed in a way that works with parallel mocha testing. + * + * @example + * + * ```js + * const { + * expectToMatchSnapshot, + * expectFileToMatchSnapshot + * } = require('../../snapshots')(); + * ``` */ -function assertFilesToMatchSnapshot(options, ...files) { - options = {exists: true, ...options}; - if (options.rootPath) { - files = files.map(f => path.resolve(options.rootPath, f)); +function install() { + const expectToMatchSnapshot = initializeSnapshots( + path.resolve(__dirname, '../snapshots'), + ); + + return { + expectToMatchSnapshot, + expectFileToMatchSnapshot, + assertFilesToMatchSnapshot, + }; + + function expectFileToMatchSnapshot(filePath) { + assert.file(filePath); + const content = fs.readFileSync(filePath, {encoding: 'utf-8'}); + expectToMatchSnapshot(content); } - for (const f of files) { - if (options.exists === false) { - assert.noFile(f); - break; + /** + * Assert a list of files to match snapshots + * @param {object} options Options + * - exists: assert the file exists or not + * - rootPath: rootPath for file names + * @param {...string} files + */ + function assertFilesToMatchSnapshot(options, ...files) { + options = {exists: true, ...options}; + if (options.rootPath) { + files = files.map(f => path.resolve(options.rootPath, f)); } - assert.file(f); - expectFileToMatchSnapshot(f); - } -} -module.exports = { - expectToMatchSnapshot, - expectFileToMatchSnapshot, - assertFilesToMatchSnapshot, + for (const f of files) { + if (options.exists === false) { + assert.noFile(f); + break; + } + assert.file(f); + expectFileToMatchSnapshot(f); + } + } }; diff --git a/packages/cli/test/unit/openapi/controller-spec.unit.js b/packages/cli/test/unit/openapi/controller-spec.unit.js index a58d0d3794bf..e82e82b123f7 100644 --- a/packages/cli/test/unit/openapi/controller-spec.unit.js +++ b/packages/cli/test/unit/openapi/controller-spec.unit.js @@ -7,7 +7,7 @@ const json5 = require('json5'); const {loadAndBuildSpec} = require('../../../generators/openapi/spec-loader'); const path = require('path'); -const {expectToMatchSnapshot} = require('../../snapshots'); +const {expectToMatchSnapshot} = require('../../snapshots')(); describe('openapi to controllers/models', () => { const customer = path.join( diff --git a/packages/cli/test/unit/openapi/schema-model.unit.js b/packages/cli/test/unit/openapi/schema-model.unit.js index 70b8aa8898aa..1784ef46f35f 100644 --- a/packages/cli/test/unit/openapi/schema-model.unit.js +++ b/packages/cli/test/unit/openapi/schema-model.unit.js @@ -12,7 +12,7 @@ const { } = require('../../../generators/openapi/schema-helper'); const path = require('path'); const json5 = require('json5'); -const {expectToMatchSnapshot} = require('../../snapshots'); +const {expectToMatchSnapshot} = require('../../snapshots')(); describe('schema to model', () => { let usptoSpec, usptoSpecAnonymous, petstoreSpec, customerSpec; From b107660a8660dcbeeaf8c3fe9682e7fa6e6e13d9 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Mon, 15 Jun 2020 14:23:29 -0700 Subject: [PATCH 4/5] chore(cli): add some tests to show the issue --- .../dummy/common.integration.snapshots.js | 12 ++++++++++++ .../dummy/test1.integration.snapshots.js | 12 ++++++++++++ .../dummy/test2.integration.snapshots.js | 12 ++++++++++++ .../test/integration/dummy/common.integration.js | 16 ++++++++++++++++ .../test/integration/dummy/test1.integration.js | 16 ++++++++++++++++ .../test/integration/dummy/test2.integration.js | 16 ++++++++++++++++ 6 files changed, 84 insertions(+) create mode 100644 packages/cli/snapshots/integration/dummy/common.integration.snapshots.js create mode 100644 packages/cli/snapshots/integration/dummy/test1.integration.snapshots.js create mode 100644 packages/cli/snapshots/integration/dummy/test2.integration.snapshots.js create mode 100644 packages/cli/test/integration/dummy/common.integration.js create mode 100644 packages/cli/test/integration/dummy/test1.integration.js create mode 100644 packages/cli/test/integration/dummy/test2.integration.js diff --git a/packages/cli/snapshots/integration/dummy/common.integration.snapshots.js b/packages/cli/snapshots/integration/dummy/common.integration.snapshots.js new file mode 100644 index 000000000000..4b6459ac2937 --- /dev/null +++ b/packages/cli/snapshots/integration/dummy/common.integration.snapshots.js @@ -0,0 +1,12 @@ +// IMPORTANT +// This snapshot file is auto-generated, but designed for humans. +// It should be checked into source control and tracked carefully. +// Re-generate by setting UPDATE_SNAPSHOTS=1 and running tests. +// Make sure to inspect the changes in the snapshots below. +// Do not ignore changes! + +'use strict'; + +exports[`common matches snapshot 1`] = ` +common result +`; diff --git a/packages/cli/snapshots/integration/dummy/test1.integration.snapshots.js b/packages/cli/snapshots/integration/dummy/test1.integration.snapshots.js new file mode 100644 index 000000000000..3ccc81ad0b42 --- /dev/null +++ b/packages/cli/snapshots/integration/dummy/test1.integration.snapshots.js @@ -0,0 +1,12 @@ +// IMPORTANT +// This snapshot file is auto-generated, but designed for humans. +// It should be checked into source control and tracked carefully. +// Re-generate by setting UPDATE_SNAPSHOTS=1 and running tests. +// Make sure to inspect the changes in the snapshots below. +// Do not ignore changes! + +'use strict'; + +exports[`common matches snapshot 1 1`] = ` +common result +`; diff --git a/packages/cli/snapshots/integration/dummy/test2.integration.snapshots.js b/packages/cli/snapshots/integration/dummy/test2.integration.snapshots.js new file mode 100644 index 000000000000..3ccc81ad0b42 --- /dev/null +++ b/packages/cli/snapshots/integration/dummy/test2.integration.snapshots.js @@ -0,0 +1,12 @@ +// IMPORTANT +// This snapshot file is auto-generated, but designed for humans. +// It should be checked into source control and tracked carefully. +// Re-generate by setting UPDATE_SNAPSHOTS=1 and running tests. +// Make sure to inspect the changes in the snapshots below. +// Do not ignore changes! + +'use strict'; + +exports[`common matches snapshot 1 1`] = ` +common result +`; diff --git a/packages/cli/test/integration/dummy/common.integration.js b/packages/cli/test/integration/dummy/common.integration.js new file mode 100644 index 000000000000..74f0241e9393 --- /dev/null +++ b/packages/cli/test/integration/dummy/common.integration.js @@ -0,0 +1,16 @@ +// Copyright IBM Corp. 2018,2020. All Rights Reserved. +// Node module: @loopback/cli +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +'use strict'; + +const {expectToMatchSnapshot} = require('../../snapshots')(); + +exports.commonTest = function () { + describe('common', () => { + it('matches snapshot 1', function () { + expectToMatchSnapshot('common result'); + }); + }); +}; diff --git a/packages/cli/test/integration/dummy/test1.integration.js b/packages/cli/test/integration/dummy/test1.integration.js new file mode 100644 index 000000000000..c9eaf47a6e4f --- /dev/null +++ b/packages/cli/test/integration/dummy/test1.integration.js @@ -0,0 +1,16 @@ +// Copyright IBM Corp. 2018,2020. All Rights Reserved. +// Node module: @loopback/cli +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +'use strict'; + +const {expectToMatchSnapshot} = require('../../snapshots')(); + +describe('test1', () => { + it('matches snapshot 1', () => { + expectToMatchSnapshot('test1 result'); + }); +}); + +require('./common.integration').commonTest(); diff --git a/packages/cli/test/integration/dummy/test2.integration.js b/packages/cli/test/integration/dummy/test2.integration.js new file mode 100644 index 000000000000..af6d0490f38e --- /dev/null +++ b/packages/cli/test/integration/dummy/test2.integration.js @@ -0,0 +1,16 @@ +// Copyright IBM Corp. 2018,2020. All Rights Reserved. +// Node module: @loopback/cli +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +'use strict'; + +const {expectToMatchSnapshot} = require('../../snapshots')(); + +describe('test2', () => { + it('matches snapshot 2', () => { + expectToMatchSnapshot('test2 result'); + }); +}); + +require('./common.integration').commonTest(); From bb72889aa7f70e7566c4bf96f62d7618372b1039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 16 Jun 2020 17:23:44 +0200 Subject: [PATCH 5/5] fixup! fix the edge case tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- .../integration/dummy/test1.integration.snapshots.js | 4 ++-- .../integration/dummy/test2.integration.snapshots.js | 4 ++-- packages/cli/test/integration/dummy/common.integration.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/cli/snapshots/integration/dummy/test1.integration.snapshots.js b/packages/cli/snapshots/integration/dummy/test1.integration.snapshots.js index 3ccc81ad0b42..7af7355ec2a0 100644 --- a/packages/cli/snapshots/integration/dummy/test1.integration.snapshots.js +++ b/packages/cli/snapshots/integration/dummy/test1.integration.snapshots.js @@ -7,6 +7,6 @@ 'use strict'; -exports[`common matches snapshot 1 1`] = ` -common result +exports[`test1 matches snapshot 1 1`] = ` +test1 result `; diff --git a/packages/cli/snapshots/integration/dummy/test2.integration.snapshots.js b/packages/cli/snapshots/integration/dummy/test2.integration.snapshots.js index 3ccc81ad0b42..17fbae77d555 100644 --- a/packages/cli/snapshots/integration/dummy/test2.integration.snapshots.js +++ b/packages/cli/snapshots/integration/dummy/test2.integration.snapshots.js @@ -7,6 +7,6 @@ 'use strict'; -exports[`common matches snapshot 1 1`] = ` -common result +exports[`test2 matches snapshot 2 1`] = ` +test2 result `; diff --git a/packages/cli/test/integration/dummy/common.integration.js b/packages/cli/test/integration/dummy/common.integration.js index 74f0241e9393..8dbeb7bc95ae 100644 --- a/packages/cli/test/integration/dummy/common.integration.js +++ b/packages/cli/test/integration/dummy/common.integration.js @@ -5,10 +5,10 @@ 'use strict'; -const {expectToMatchSnapshot} = require('../../snapshots')(); - exports.commonTest = function () { describe('common', () => { + const {expectToMatchSnapshot} = require('../../snapshots')(); + it('matches snapshot 1', function () { expectToMatchSnapshot('common result'); });