From 8ec58dff0bb8ec57294892a46afa568c47364404 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 Nov 2023 04:31:30 +0000 Subject: [PATCH 1/2] chore(deps-dev): bump yeoman-environment from 3.19.3 to 4.1.3 Bumps [yeoman-environment](https://github.com/yeoman/environment) from 3.19.3 to 4.1.3. - [Release notes](https://github.com/yeoman/environment/releases) - [Commits](https://github.com/yeoman/environment/compare/v3.19.3...v4.1.3) --- updated-dependencies: - dependency-name: yeoman-environment dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 46413eb..353bb69 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "jest": "^29", "stdout-stderr": "^0.1.13", "yeoman-assert": "^3.1.1", - "yeoman-environment": "^3.2.0", + "yeoman-environment": "^4.1.3", "yeoman-test": "^6.0.0" }, "dependencies": { From 6eb183339922ca5559b9bcba1339b51651a1f494 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Thu, 18 Jan 2024 19:06:51 +0800 Subject: [PATCH 2/2] fix: update and use yeoman-test to v8 (use dynamic import) --- jest.config.js | 3 +- package.json | 11 +++--- test/generators/add-action/index.test.js | 29 ++++++++------- test/generators/add-ci/index.test.js | 8 +++-- test/generators/add-events/index.test.js | 12 ++++--- .../add-events/publish-events.test.js | 12 ++++--- .../add-vscode-config/index.test.js | 36 ++++++++++--------- test/generators/add-web-assets/index.test.js | 21 ++++++----- test/generators/application/index.test.js | 26 ++++++++------ test/generators/base-app/index.test.js | 9 +++-- 10 files changed, 101 insertions(+), 66 deletions(-) diff --git a/jest.config.js b/jest.config.js index 0da9b06..6ea5c79 100644 --- a/jest.config.js +++ b/jest.config.js @@ -29,7 +29,8 @@ module.exports = { global: { branches: 100, lines: 100, - statements: 100 + statements: 100, + functions: 100 } } } diff --git a/package.json b/package.json index 4c3537a..5c5079d 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "npm run lint && npm run unit-tests", "lint": "eslint .", - "unit-tests": "jest -c ./jest.config.js" + "unit-tests": "cross-env NODE_OPTIONS=--experimental-vm-modules ./node_modules/jest/bin/jest.js -c ./jest.config.js" }, "repository": { "type": "git", @@ -29,6 +29,7 @@ "homepage": "https://github.com/adobe/generator-aio-app#readme", "devDependencies": { "@types/jest": "^29", + "cross-env": "^7.0.3", "eol": "^0.9.1", "eslint": "^8", "eslint-config-standard": "^17", @@ -40,17 +41,17 @@ "jest": "^29", "stdout-stderr": "^0.1.13", "yeoman-assert": "^3.1.1", - "yeoman-environment": "^4.1.3", - "yeoman-test": "^6.0.0" + "yeoman-environment": "^4", + "yeoman-test": "^8" }, "dependencies": { "@adobe/aio-lib-env": "^3", "@adobe/generator-add-action-analytics": "^1", + "@adobe/generator-add-action-asset-compute": "^2", "@adobe/generator-add-action-campaign-standard": "^1", "@adobe/generator-add-action-customer-profile": "^1", - "@adobe/generator-add-action-target": "^1", "@adobe/generator-add-action-generic": "^1", - "@adobe/generator-add-action-asset-compute": "^2", + "@adobe/generator-add-action-target": "^1", "@adobe/generator-add-web-assets-exc-raw-html": "^1", "@adobe/generator-add-web-assets-exc-react": "^1", "@adobe/generator-app-asset-compute": "^2", diff --git a/test/generators/add-action/index.test.js b/test/generators/add-action/index.test.js index d27fb51..63c7671 100644 --- a/test/generators/add-action/index.test.js +++ b/test/generators/add-action/index.test.js @@ -8,7 +8,6 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -const helpers = require('yeoman-test') const { utils, constants } = require('@adobe/generator-app-common-lib') const AddActions = require('../../../generators/add-action') @@ -57,6 +56,12 @@ const expectedChoices = { // spies const prompt = jest.spyOn(Generator.prototype, 'prompt') const composeWith = jest.spyOn(Generator.prototype, 'composeWith') + +let yeomanTestHelpers +beforeAll(async () => { + yeomanTestHelpers = (await import('yeoman-test')).default +}) + beforeAll(() => { // mock implementations composeWith.mockReturnValue(undefined) @@ -80,7 +85,7 @@ describe('run', () => { const options = cloneDeep(global.basicGeneratorOptions) options['skip-prompt'] = true options['adobe-services'] = `${sdkCodes.analytics},${sdkCodes.target},${sdkCodes.campaign},${sdkCodes.customerProfile}` - await helpers.run(AddActions) + await yeomanTestHelpers.run(AddActions) .withOptions(options) // with skip prompt defaults to generic action // make sure sub generators have been called @@ -91,7 +96,7 @@ describe('run', () => { }) test('no input, selects one generator', async () => { - await helpers.run(AddActions) + await yeomanTestHelpers.run(AddActions) .withPrompts({ actionGenerators: ['a'] }) expect(prompt).toHaveBeenCalledTimes(1) @@ -117,7 +122,7 @@ describe('run', () => { })) }) test('no input, selects multiple generators', async () => { - await helpers.run(AddActions) + await yeomanTestHelpers.run(AddActions) .withPrompts({ actionGenerators: ['a', 'b', 'c'] }) expect(prompt).toHaveBeenCalledTimes(1) @@ -146,7 +151,7 @@ describe('run', () => { const options = cloneDeep(global.basicGeneratorOptions) options['adobe-services'] = 'NOTEXITING' options['--adobe-supported-services'] = 'notexistting' - await helpers.run(AddActions) + await yeomanTestHelpers.run(AddActions) .withOptions(options) .withPrompts({ actionGenerators: ['a', 'b', 'c'] }) @@ -175,7 +180,7 @@ describe('run', () => { test('--adobe-services="analytics,customerProfile"', async () => { const options = cloneDeep(global.basicGeneratorOptions) options['adobe-services'] = `${sdkCodes.analytics},${sdkCodes.customerProfile}` - await helpers.run(AddActions) + await yeomanTestHelpers.run(AddActions) .withOptions(options) .withPrompts({ actionGenerators: ['a', 'b', 'c'] }) @@ -206,7 +211,7 @@ describe('run', () => { const options = cloneDeep(global.basicGeneratorOptions) options['adobe-services'] = `${sdkCodes.analytics},${sdkCodes.customerProfile}` options['supported-adobe-services'] = `${sdkCodes.analytics},${sdkCodes.assetCompute},${sdkCodes.customerProfile},${sdkCodes.target}` - await helpers.run(AddActions) + await yeomanTestHelpers.run(AddActions) .withOptions(options) .withPrompts({ actionGenerators: ['a', 'b', 'c'] }) @@ -239,7 +244,7 @@ describe('run', () => { const options = cloneDeep(global.basicGeneratorOptions) options['adobe-services'] = `${sdkCodes.analytics},${sdkCodes.customerProfile}` options['supported-adobe-services'] = `${sdkCodes.analytics},${sdkCodes.assetCompute},${sdkCodes.customerProfile},${sdkCodes.campaign},${sdkCodes.target}` - await helpers.run(AddActions) + await yeomanTestHelpers.run(AddActions) .withOptions(options) .withPrompts({ actionGenerators: ['a', 'b', 'c'] }) @@ -271,7 +276,7 @@ describe('run', () => { const options = cloneDeep(global.basicGeneratorOptions) options['adobe-services'] = `${sdkCodes.analytics},${sdkCodes.assetCompute},${sdkCodes.customerProfile},${sdkCodes.campaign},${sdkCodes.target}` options['supported-adobe-services'] = `${sdkCodes.analytics},${sdkCodes.assetCompute},${sdkCodes.customerProfile},${sdkCodes.campaign},${sdkCodes.target}` - await helpers.run(AddActions) + await yeomanTestHelpers.run(AddActions) .withOptions(options) .withPrompts({ actionGenerators: ['a', 'b', 'c'] }) @@ -301,7 +306,7 @@ describe('run', () => { test('--adobe-services=ALL', async () => { const options = cloneDeep(global.basicGeneratorOptions) options['adobe-services'] = `${sdkCodes.analytics},${sdkCodes.assetCompute},${sdkCodes.customerProfile},${sdkCodes.campaign},${sdkCodes.target}` - await helpers.run(AddActions) + await yeomanTestHelpers.run(AddActions) .withOptions({ 'adobe-services': `${sdkCodes.analytics},${sdkCodes.assetCompute},${sdkCodes.customerProfile},${sdkCodes.campaign},${sdkCodes.target}` }) @@ -334,7 +339,7 @@ describe('run', () => { const options = cloneDeep(global.basicGeneratorOptions) options['adobe-services'] = '' options['supported-adobe-services'] = `${sdkCodes.analytics},${sdkCodes.assetCompute},${sdkCodes.customerProfile},${sdkCodes.target}` - await helpers.run(AddActions) + await yeomanTestHelpers.run(AddActions) .withOptions(options) .withPrompts({ actionGenerators: ['a', 'b', 'c'] }) @@ -367,7 +372,7 @@ describe('run', () => { const options = cloneDeep(global.basicGeneratorOptions) options['adobe-services'] = '' options['supported-adobe-services'] = `${sdkCodes.analytics},${sdkCodes.assetCompute},${sdkCodes.customerProfile},${sdkCodes.campaign},${sdkCodes.target}` - await helpers.run(AddActions) + await yeomanTestHelpers.run(AddActions) .withOptions(options) .withPrompts({ actionGenerators: ['a', 'b', 'c'] }) diff --git a/test/generators/add-ci/index.test.js b/test/generators/add-ci/index.test.js index fb86191..c01c21a 100644 --- a/test/generators/add-ci/index.test.js +++ b/test/generators/add-ci/index.test.js @@ -11,7 +11,6 @@ governing permissions and limitations under the License. /* eslint-disable jest/expect-expect */ // => use assert -const helpers = require('yeoman-test') const assert = require('yeoman-assert') const fs = require('fs') const path = require('path') @@ -19,6 +18,11 @@ const path = require('path') const theGeneratorPath = require.resolve('../../../generators/add-ci') const Generator = require('yeoman-generator') +let yeomanTestHelpers +beforeAll(async () => { + yeomanTestHelpers = (await import('yeoman-test')).default +}) + describe('prototype', () => { test('exports a yeoman generator', () => { expect(require(theGeneratorPath).prototype).toBeInstanceOf(Generator) @@ -27,7 +31,7 @@ describe('prototype', () => { describe('run', () => { test('should create files under .github', async () => { - await helpers.run(theGeneratorPath) + await yeomanTestHelpers.run(theGeneratorPath) .inTmpDir(dir => { fs.writeFileSync(path.join(dir, '.env'), 'FAKECONTENT') }) diff --git a/test/generators/add-events/index.test.js b/test/generators/add-events/index.test.js index 36ad64e..e029175 100644 --- a/test/generators/add-events/index.test.js +++ b/test/generators/add-events/index.test.js @@ -8,8 +8,6 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -const helpers = require('yeoman-test') - const theGeneratorPath = require.resolve('../../../generators/add-events') const Generator = require('yeoman-generator') const cloneDeep = require('lodash.clonedeep') @@ -17,7 +15,13 @@ const cloneDeep = require('lodash.clonedeep') // spies const prompt = jest.spyOn(Generator.prototype, 'prompt') const composeWith = jest.spyOn(Generator.prototype, 'composeWith') -beforeAll(() => { + +let yeomanTestHelpers +beforeAll(async () => { + yeomanTestHelpers = (await import('yeoman-test')).default +}) + +beforeAll(async () => { // mock implementations composeWith.mockReturnValue(undefined) }) @@ -43,7 +47,7 @@ describe('run', () => { test('--skip-prompt "', async () => { const options = cloneDeep(global.basicGeneratorOptions) options['skip-prompt'] = true - await helpers.run(theGeneratorPath) + await yeomanTestHelpers.run(theGeneratorPath) .withOptions(options) // with skip prompt defaults to generic action // make sure sub generators have been called diff --git a/test/generators/add-events/publish-events.test.js b/test/generators/add-events/publish-events.test.js index 1161766..6939baa 100644 --- a/test/generators/add-events/publish-events.test.js +++ b/test/generators/add-events/publish-events.test.js @@ -10,7 +10,6 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -const helpers = require('yeoman-test') const assert = require('yeoman-assert') const fs = require('fs') const yaml = require('js-yaml') @@ -22,6 +21,11 @@ const Generator = require('yeoman-generator') const { constants } = require('@adobe/generator-app-common-lib') +let yeomanTestHelpers +beforeAll(async () => { + yeomanTestHelpers = (await import('yeoman-test')).default +}) + describe('prototype', () => { test('exports a yeoman generator', () => { expect(require(theGeneratorPath).prototype).toBeInstanceOf(Generator) @@ -93,7 +97,7 @@ describe('run', () => { options['skip-prompt'] = true const prevDotEnvContent = 'PREVIOUSCONTENT\n' try { - await helpers.run(theGeneratorPath) + await yeomanTestHelpers.run(theGeneratorPath) .withOptions(options) .inTmpDir(dir => { fs.writeFileSync(path.join(dir, '.env'), prevDotEnvContent) @@ -121,7 +125,7 @@ describe('run', () => { const prevDotEnvContent = 'PREVIOUSCONTENT\n' const options = cloneDeep(global.basicGeneratorOptions) options['skip-prompt'] = true - await helpers.run(theGeneratorPath) + await yeomanTestHelpers.run(theGeneratorPath) .withOptions(options) .inTmpDir(dir => { fs.writeFileSync('ext.config.yaml', yaml.dump({ @@ -157,7 +161,7 @@ describe('run', () => { const prevDotEnvContent = 'PREVIOUSCONTENT\n' const options = cloneDeep(global.basicGeneratorOptions) options['skip-prompt'] = false - await helpers.run(theGeneratorPath) + await yeomanTestHelpers.run(theGeneratorPath) .withOptions(options) .withPrompts({ actionName: 'fakeAction' }) .inTmpDir(dir => { diff --git a/test/generators/add-vscode-config/index.test.js b/test/generators/add-vscode-config/index.test.js index c9e6aa1..2d3d44c 100644 --- a/test/generators/add-vscode-config/index.test.js +++ b/test/generators/add-vscode-config/index.test.js @@ -8,13 +8,17 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -const helpers = require('yeoman-test') const assert = require('yeoman-assert') const fs = require('fs-extra') const path = require('path') jest.mock('fs-extra') +let yeomanTestHelpers +beforeAll(async () => { + yeomanTestHelpers = (await import('yeoman-test')).default +}) + const theGeneratorPath = require.resolve('../../../generators/add-vscode-config') const Generator = require('yeoman-generator') const { constants } = require('@adobe/generator-app-common-lib') @@ -147,7 +151,7 @@ test('option app-config incomplete', async () => { } } } - const result = helpers.run(theGeneratorPath).withOptions(options) + const result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).rejects.toEqual(new Error( 'App config missing keys: app.hasFrontend, app.hasBackend, root')) @@ -159,7 +163,7 @@ test('option backend keys missing', async () => { options['app-config'].app.hasFrontend = false delete options['app-config'].manifest - const result = helpers.run(theGeneratorPath).withOptions(options) + const result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).rejects.toEqual(new Error('App config missing keys: manifest.packagePlaceholder, manifest.full.packages')) }) @@ -170,7 +174,7 @@ test('option frontend-url missing', async () => { options['frontend-url'] = undefined options['env-file'] = 'env-file' - const result = helpers.run(theGeneratorPath).withOptions(options) + const result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).rejects.toEqual(new Error('Missing option for generator: frontend-url')) }) @@ -181,7 +185,7 @@ test('option env-file missing', async () => { options['frontend-url'] = 'https://localhost:9999' delete options['env-file'] - const result = helpers.run(theGeneratorPath).withOptions(options) + const result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).rejects.toEqual(new Error('Missing option for generator: env-file')) }) @@ -194,7 +198,7 @@ test('no missing options -- coverage (no frontend or backend, runtime not specif isDirectory: () => false }) - const result = helpers.run(theGeneratorPath).withOptions(options) + const result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).resolves.not.toThrow() }) @@ -208,7 +212,7 @@ test('no missing options (action is a file)', async () => { isDirectory: () => false }) - const result = helpers.run(theGeneratorPath).withOptions(options) + const result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).resolves.not.toThrow() assert.file(options['destination-file']) // destination file is written @@ -230,7 +234,7 @@ test('no missing options (action is a folder)', async () => { }) fs.readJsonSync.mockReturnValue({}) // no main property in package.json - result = helpers.run(theGeneratorPath).withOptions(options) + result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).resolves.not.toThrow() assert.file(destFile) // destination file is written @@ -243,7 +247,7 @@ test('no missing options (action is a folder)', async () => { ) fs.readJsonSync.mockReturnValue({ main: 'main.js' }) // has main property in package.json - result = helpers.run(theGeneratorPath).withOptions(options) + result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).resolves.not.toThrow() assert.file(destFile) // destination file is written @@ -265,7 +269,7 @@ test('no missing options (coverage: action has a runtime specifier)', async () = isDirectory: () => false }) - const result = helpers.run(theGeneratorPath).withOptions(options) + const result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).resolves.not.toThrow() }) @@ -279,7 +283,7 @@ test('no missing options (coverage: action has annotations)', async () => { isDirectory: () => false }) - const result = helpers.run(theGeneratorPath).withOptions(options) + const result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).resolves.not.toThrow() }) @@ -297,7 +301,7 @@ test('output check', async () => { isDirectory: () => false }) - const result = helpers.run(theGeneratorPath).withOptions(options) + const result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).resolves.not.toThrow() const destFile = options['destination-file'] @@ -319,7 +323,7 @@ test('output check (action path is absolute)', async () => { isDirectory: () => false }) - const result = helpers.run(theGeneratorPath).withOptions(options) + const result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).resolves.not.toThrow() const destFile = options['destination-file'] @@ -341,7 +345,7 @@ test('output check (envFile path is absolute)', async () => { isDirectory: () => false }) - const result = helpers.run(theGeneratorPath).withOptions(options) + const result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).resolves.not.toThrow() const destFile = options['destination-file'] @@ -366,7 +370,7 @@ test('output check (custom package)', async () => { isDirectory: () => false }) - const result = helpers.run(theGeneratorPath).withOptions(options) + const result = yeomanTestHelpers.run(theGeneratorPath).withOptions(options) await expect(result).resolves.not.toThrow() const destFile = options['destination-file'] @@ -384,7 +388,7 @@ test('vscode launch configuration exists', async () => { fs.existsSync.mockReturnValue(true) // destination file exists - const result = helpers + const result = yeomanTestHelpers .run(theGeneratorPath) .withOptions(options) .withPrompts({ overwriteVsCodeConfig: false }) diff --git a/test/generators/add-web-assets/index.test.js b/test/generators/add-web-assets/index.test.js index f7a6f0e..30ae265 100644 --- a/test/generators/add-web-assets/index.test.js +++ b/test/generators/add-web-assets/index.test.js @@ -8,7 +8,6 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -const helpers = require('yeoman-test') const path = require('path') const fs = require('fs-extra') const { utils } = require('@adobe/generator-app-common-lib') @@ -22,7 +21,13 @@ const Generator = require('yeoman-generator') // spies const prompt = jest.spyOn(Generator.prototype, 'prompt') const composeWith = jest.spyOn(Generator.prototype, 'composeWith') -beforeAll(() => { + +let yeomanTestHelpers +beforeAll(async () => { + yeomanTestHelpers = (await import('yeoman-test')).default +}) + +beforeAll(async () => { // mock implementations composeWith.mockReturnValue(undefined) }) @@ -58,7 +63,7 @@ describe('run', () => { options['project-name'] = 'fake' options['adobe-services'] = 'some,string' options['web-src-folder'] = 'web-src' - await expect(helpers.run(AddWebAssets) + await expect(yeomanTestHelpers.run(AddWebAssets) .withOptions(options) .inTmpDir(dir => { fs.mkdirSync(path.join(dir, 'web-src')) @@ -70,7 +75,7 @@ describe('run', () => { options['skip-prompt'] = true options['web-src-folder'] = 'web-src' let tmpDir - await helpers.run(AddWebAssets) + await yeomanTestHelpers.run(AddWebAssets) .withOptions(options) .inTmpDir(dir => { tmpDir = dir @@ -94,7 +99,7 @@ describe('run', () => { options['web-src-folder'] = 'web-src' options['has-backend'] = false let tmpDir - await helpers.run(AddWebAssets) + await yeomanTestHelpers.run(AddWebAssets) .withOptions(options) .inTmpDir(dir => { tmpDir = dir @@ -117,7 +122,7 @@ describe('run', () => { options['skip-prompt'] = true options['web-src-folder'] = 'web-src' options['project-name'] = 'fake' - await helpers.run(AddWebAssets) + await yeomanTestHelpers.run(AddWebAssets) .withOptions(options) expect(composeWith).toHaveBeenCalledTimes(1) @@ -134,7 +139,7 @@ describe('run', () => { options['web-src-folder'] = 'web-src' options['project-name'] = 'fake' options['adobe-services'] = 'some,string' - await helpers.run(AddWebAssets) + await yeomanTestHelpers.run(AddWebAssets) .withOptions(options) expect(composeWith).toHaveBeenCalledTimes(1) @@ -149,7 +154,7 @@ describe('run', () => { const options = cloneDeep(global.basicGeneratorOptions) options['web-src-folder'] = 'web-src' options['project-name'] = 'fake' - await helpers.run(AddWebAssets) + await yeomanTestHelpers.run(AddWebAssets) .withOptions(options) .withPrompts({ webAssetsGenerator: 'a' }) diff --git a/test/generators/application/index.test.js b/test/generators/application/index.test.js index d6c28d7..9115a63 100644 --- a/test/generators/application/index.test.js +++ b/test/generators/application/index.test.js @@ -11,8 +11,6 @@ governing permissions and limitations under the License. const path = require('path') -const helpers = require('yeoman-test') - const theGeneratorPath = require.resolve('../../../generators/application') const Generator = require('yeoman-generator') const { utils } = require('@adobe/generator-app-common-lib') @@ -20,7 +18,13 @@ const { utils } = require('@adobe/generator-app-common-lib') // spies const composeWith = jest.spyOn(Generator.prototype, 'composeWith') const writeKeyAppConfig = jest.spyOn(utils, 'writeKeyAppConfig') -beforeAll(() => { + +let yeomanTestHelpers +beforeAll(async () => { + yeomanTestHelpers = (await import('yeoman-test')).default +}) + +beforeAll(async () => { composeWith.mockReturnValue(undefined) writeKeyAppConfig.mockReturnValue(undefined) }) @@ -49,7 +53,7 @@ describe('prototype', () => { describe('run', () => { test('--skip-prompt --project-name fake', async () => { - await helpers.run(theGeneratorPath) + await yeomanTestHelpers.run(theGeneratorPath) .withOptions({ 'skip-prompt': true, 'project-name': 'fake-name', 'skip-install': false }) expect(composeWith).toHaveBeenCalledTimes(3) @@ -63,7 +67,7 @@ describe('run', () => { }) test('--skip-prompt --adobe-services some,string', async () => { - await helpers.run(theGeneratorPath) + await yeomanTestHelpers.run(theGeneratorPath) .withOptions({ 'skip-prompt': true, 'adobe-services': 'some,string', 'skip-install': false }) expect(composeWith).toHaveBeenCalledTimes(3) @@ -77,7 +81,7 @@ describe('run', () => { }) test('--adobe-services some,string --supported-adobe-services="" and prompt selection "actions"', async () => { - await helpers.run(theGeneratorPath) + await yeomanTestHelpers.run(theGeneratorPath) .withOptions({ 'adobe-services': 'some,string', 'supported-adobe-services': '', 'skip-install': false }) .withPrompts({ components: ['actions'] }) @@ -89,7 +93,7 @@ describe('run', () => { }) test('--adobe-services some,string and prompt selection "events"', async () => { - await helpers.run(theGeneratorPath) + await yeomanTestHelpers.run(theGeneratorPath) .withOptions({ 'adobe-services': 'some,string', 'skip-install': false }) .withPrompts({ components: ['events'] }) @@ -100,7 +104,7 @@ describe('run', () => { }) test('--adobe-services some,string and prompt selection "web-assets"', async () => { - await helpers.run(theGeneratorPath) + await yeomanTestHelpers.run(theGeneratorPath) .withOptions({ 'adobe-services': 'some,string', 'skip-install': false }) .withPrompts({ components: ['webAssets'] }) @@ -111,7 +115,7 @@ describe('run', () => { expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.web'), 'web-src') }) test('--adobe-services some,string --supported-adobe-service=some,other,string and prompt selection "web-assets, actions"', async () => { - await helpers.run(theGeneratorPath) + await yeomanTestHelpers.run(theGeneratorPath) .withOptions({ 'adobe-services': 'some,string', 'supported-adobe-services': 'some,other,string', 'skip-install': false }) .withPrompts({ components: ['webAssets', 'actions'] }) @@ -124,7 +128,7 @@ describe('run', () => { expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.web'), 'web-src') }) test('--adobe-services some,string --supported-adobe-service=some,other,string and prompt selection "web-assets, actions, events"', async () => { - await helpers.run(theGeneratorPath) + await yeomanTestHelpers.run(theGeneratorPath) .withOptions({ 'adobe-services': 'some,string', 'supported-adobe-services': 'some,other,string', 'skip-install': false }) .withPrompts({ components: ['webAssets', 'actions', 'events'] }) @@ -138,7 +142,7 @@ describe('run', () => { expect(writeKeyAppConfig).toHaveBeenCalledWith(expect.any(Generator), expect.stringContaining('application.web'), 'web-src') }) test('--skip-prompt --skip-install', async () => { - await helpers.run(theGeneratorPath) + await yeomanTestHelpers.run(theGeneratorPath) .withOptions({ 'skip-prompt': true, 'skip-install': true }) expect(composeWith).toHaveBeenCalledTimes(3) diff --git a/test/generators/base-app/index.test.js b/test/generators/base-app/index.test.js index 51558a9..82e9596 100644 --- a/test/generators/base-app/index.test.js +++ b/test/generators/base-app/index.test.js @@ -11,11 +11,14 @@ governing permissions and limitations under the License. /* eslint-disable jest/expect-expect */ // => use assert -const helpers = require('yeoman-test') - const theGeneratorPath = require.resolve('../../../generators/base-app/') const Generator = require('yeoman-generator') +let yeomanTestHelpers +beforeAll(async () => { + yeomanTestHelpers = (await import('yeoman-test')).default +}) + describe('prototype', () => { test('exports a yeoman generator', () => { expect(require(theGeneratorPath).prototype).toBeInstanceOf(Generator) @@ -26,7 +29,7 @@ describe('run', () => { test('basic ext generator', async () => { const options = { 'skip-prompt': true } - const ret = await helpers.run(theGeneratorPath) + const ret = await yeomanTestHelpers.run(theGeneratorPath) .withOptions(options) expect(ret).toBeDefined() ret.assertFile('.env')