From 99beadc501daa05db4eb08f74969bef5e58d7abf Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Thu, 3 Aug 2023 14:36:25 +0530 Subject: [PATCH 1/2] fix: export plugin test cases --- packages/contentstack-export/package.json | 1 + .../src/export/modules/locales.ts | 3 ++- .../test/integration/custom-roles.test.js | 4 ---- .../test/integration/global-fields.test.js | 20 ++++++++----------- .../test/integration/locales.test.js | 3 --- .../test/integration/marketplace-apps.test.js | 2 +- .../test/integration/webhooks.test.js | 4 ---- .../test/integration/workflows.test.js | 20 ++++++++----------- 8 files changed, 20 insertions(+), 37 deletions(-) diff --git a/packages/contentstack-export/package.json b/packages/contentstack-export/package.json index e9a1149102..f109661ef1 100644 --- a/packages/contentstack-export/package.json +++ b/packages/contentstack-export/package.json @@ -62,6 +62,7 @@ "lint": "eslint src/**/*.ts", "format": "eslint src/**/*.ts --fix", "test:integration": "INTEGRATION_TEST=true mocha --config ./test/.mocharc.js --forbid-only \"test/run.test.js\"", + "test:integration:report": "INTEGRATION_TEST=true nyc --extension .js mocha --config ./test/.mocharc.js --forbid-only \"test/run.test.js\"", "test:unit": "mocha --forbid-only \"test/unit/*.test.ts\"" }, "engines": { diff --git a/packages/contentstack-export/src/export/modules/locales.ts b/packages/contentstack-export/src/export/modules/locales.ts index 365efc78d4..5043882215 100644 --- a/packages/contentstack-export/src/export/modules/locales.ts +++ b/packages/contentstack-export/src/export/modules/locales.ts @@ -81,7 +81,8 @@ export default class LocaleExport extends BaseClass { delete locale[key]; } } - if (locale.code === this.exportConfig.master_locale.code) { + + if (locale?.code === this.exportConfig?.master_locale?.code) { this.masterLocale[locale.uid] = locale; } else { this.locales[locale.uid] = locale; diff --git a/packages/contentstack-export/test/integration/custom-roles.test.js b/packages/contentstack-export/test/integration/custom-roles.test.js index a2dd74c16f..eab4871ebc 100644 --- a/packages/contentstack-export/test/integration/custom-roles.test.js +++ b/packages/contentstack-export/test/integration/custom-roles.test.js @@ -17,10 +17,6 @@ module.exports = (region) => { : path.join(__dirname, '..', '..', `${EXPORT_PATH}_${stack}`); const customRolesBasePath = path.join(exportBasePath, modules.customRoles.dirName); const customRolesJson = path.join(customRolesBasePath, modules.customRoles.fileName); - const messageFilePath = path.join(__dirname, '..', '..', 'messages/index.json'); - - messageHandler.init({ messageFilePath }); - const { promptMessageList } = require(messageFilePath); describe('ContentStack-Export custom-roles', () => { describe('cm:stacks:export custom-roles [auth-token]', () => { diff --git a/packages/contentstack-export/test/integration/global-fields.test.js b/packages/contentstack-export/test/integration/global-fields.test.js index 8d7ada352e..a6a0fa3323 100644 --- a/packages/contentstack-export/test/integration/global-fields.test.js +++ b/packages/contentstack-export/test/integration/global-fields.test.js @@ -1,10 +1,9 @@ -let defaultConfig = require('../../src/config/default'); const fs = require('fs'); const path = require('path'); const { test } = require('@oclif/test'); const { cliux: cliUX, messageHandler } = require('@contentstack/cli-utilities'); -const { default: config } = require('../../src/config'); +const { default: config } = require('../../lib/config'); const modules = config.modules; const { getStackDetailsByRegion, getGlobalFieldsCount, cleanUp, checkCounts } = require('./utils/helper'); const { EXPORT_PATH, DEFAULT_TIMEOUT } = require('./config.json'); @@ -18,20 +17,17 @@ module.exports = (region) => { : path.join(__dirname, '..', '..', `${EXPORT_PATH}_${stack}`); const globalFieldsBasePath = path.join(exportBasePath, modules.globalfields.dirName); const globalFieldsJson = path.join(globalFieldsBasePath, modules.globalfields.fileName); - const messageFilePath = path.join(__dirname, '..', '..', 'messages/index.json'); - - messageHandler.init({ messageFilePath }); - const { promptMessageList } = require(messageFilePath); describe('ContentStack-Export global-fields', () => { describe('cm:stacks:export global-fields [auth-token]', () => { test .timeout(DEFAULT_TIMEOUT || 600000) // NOTE setting default timeout as 10 minutes - .stub(cliUX, 'prompt', async (name) => { + .stub(cliUX, 'inquire', async (input) => { + const { name } = input; switch (name) { - case promptMessageList.promptSourceStack: + case 'apiKey': return stackDetails[stack].STACK_API_KEY; - case promptMessageList.promptPathStoredData: + case 'dir': return `${EXPORT_PATH}_${stack}`; } }) @@ -85,9 +81,9 @@ module.exports = (region) => { afterEach(async () => { await cleanUp(path.join(__dirname, '..', '..', `${EXPORT_PATH}_${stack}`)); - defaultConfig.management_token = undefined; - defaultConfig.branch = undefined; - defaultConfig.branches = []; + config.management_token = undefined; + config.branch = undefined; + config.branches = []; }); } }; diff --git a/packages/contentstack-export/test/integration/locales.test.js b/packages/contentstack-export/test/integration/locales.test.js index 03d42c115d..d0e95fd217 100644 --- a/packages/contentstack-export/test/integration/locales.test.js +++ b/packages/contentstack-export/test/integration/locales.test.js @@ -18,9 +18,6 @@ module.exports = (region) => { const localeBasePath = path.join(exportBasePath, modules.locales.dirName); const localeJson = path.join(localeBasePath, modules.locales.fileName); - const messageFilePath = path.join(__dirname, '..', '..', 'messages/index.json'); - messageHandler.init({ messageFilePath }); - const { promptMessageList } = require(messageFilePath); describe('ContentStack-Export locales', () => { describe('cm:stacks:export locales [auth-token]', () => { diff --git a/packages/contentstack-export/test/integration/marketplace-apps.test.js b/packages/contentstack-export/test/integration/marketplace-apps.test.js index 5ee81acf39..2c224d9d1e 100644 --- a/packages/contentstack-export/test/integration/marketplace-apps.test.js +++ b/packages/contentstack-export/test/integration/marketplace-apps.test.js @@ -1,7 +1,7 @@ const fs = require('fs'); const path = require('path'); const { test } = require('@oclif/test'); -const { cliux: cliUX, messageHandler } = require('@contentstack/cli-utilities'); +const { cliux: cliUX } = require('@contentstack/cli-utilities'); const { default: config } = require('../../lib/config'); const modules = config.modules; diff --git a/packages/contentstack-export/test/integration/webhooks.test.js b/packages/contentstack-export/test/integration/webhooks.test.js index f1705a8af9..14fc5ccac3 100644 --- a/packages/contentstack-export/test/integration/webhooks.test.js +++ b/packages/contentstack-export/test/integration/webhooks.test.js @@ -17,10 +17,6 @@ module.exports = (region) => { : path.join(__dirname, '..', '..', `${EXPORT_PATH}_${stack}`); const webhooksBasePath = path.join(exportBasePath, modules.webhooks.dirName); const webhooksJson = path.join(webhooksBasePath, modules.webhooks.fileName); - const messageFilePath = path.join(__dirname, '..', '..', 'messages/index.json'); - - messageHandler.init({ messageFilePath }); - const { promptMessageList } = require(messageFilePath); describe('ContentStack-Export webhooks', () => { describe('cm:stacks:export webhooks [auth-token]', () => { diff --git a/packages/contentstack-export/test/integration/workflows.test.js b/packages/contentstack-export/test/integration/workflows.test.js index 4fc624915c..f9e40564e3 100644 --- a/packages/contentstack-export/test/integration/workflows.test.js +++ b/packages/contentstack-export/test/integration/workflows.test.js @@ -1,10 +1,9 @@ -let defaultConfig = require('../../src/config/default'); const fs = require('fs'); const path = require('path'); const { test } = require('@oclif/test'); const { cliux: cliUX, messageHandler } = require('@contentstack/cli-utilities'); -const { default: config } = require('../../src/config'); +const { default: config } = require('../../lib/config'); const modules = config.modules; const { getStackDetailsByRegion, getWorkflowsCount, cleanUp, checkCounts } = require('./utils/helper'); const { EXPORT_PATH, DEFAULT_TIMEOUT } = require('./config.json'); @@ -18,20 +17,17 @@ module.exports = (region) => { : path.join(__dirname, '..', '..', `${EXPORT_PATH}_${stack}`); const workflowsBasePath = path.join(exportBasePath, modules.workflows.dirName); const workflowsJson = path.join(workflowsBasePath, modules.workflows.fileName); - const messageFilePath = path.join(__dirname, '..', '..', 'messages/index.json'); - - messageHandler.init({ messageFilePath }); - const { promptMessageList } = require(messageFilePath); describe('ContentStack-Export workflows', () => { describe('cm:stacks:export workfows [auth-token]', () => { test .timeout(DEFAULT_TIMEOUT || 600000) // NOTE setting default timeout as 10 minutes - .stub(cliUX, 'prompt', async (name) => { + .stub(cliUX, 'inquire', async (input) => { + const { name } = input; switch (name) { - case promptMessageList.promptSourceStack: + case 'apiKey': return stackDetails[stack].STACK_API_KEY; - case promptMessageList.promptPathStoredData: + case 'dir': return `${EXPORT_PATH}_${stack}`; } }) @@ -85,9 +81,9 @@ module.exports = (region) => { afterEach(async () => { await cleanUp(path.join(__dirname, '..', '..', `${EXPORT_PATH}_${stack}`)); - defaultConfig.management_token = undefined; - defaultConfig.branch = undefined; - defaultConfig.branches = []; + config.management_token = undefined; + config.branch = undefined; + config.branches = []; }); } }; From 01ee9b36bc9df09ea01070a7f0030a5b16f09a34 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Thu, 3 Aug 2023 15:21:12 +0530 Subject: [PATCH 2/2] refactor: test report --- packages/contentstack-export/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contentstack-export/package.json b/packages/contentstack-export/package.json index f109661ef1..6534551533 100644 --- a/packages/contentstack-export/package.json +++ b/packages/contentstack-export/package.json @@ -62,7 +62,7 @@ "lint": "eslint src/**/*.ts", "format": "eslint src/**/*.ts --fix", "test:integration": "INTEGRATION_TEST=true mocha --config ./test/.mocharc.js --forbid-only \"test/run.test.js\"", - "test:integration:report": "INTEGRATION_TEST=true nyc --extension .js mocha --config ./test/.mocharc.js --forbid-only \"test/run.test.js\"", + "test:integration:report": "INTEGRATION_TEST=true nyc --extension .js mocha --forbid-only \"test/run.test.js\"", "test:unit": "mocha --forbid-only \"test/unit/*.test.ts\"" }, "engines": {