From 4fba96256a1988140c9e5d62ac6a1390bcb71cf0 Mon Sep 17 00:00:00 2001 From: Gilad Shoham Date: Wed, 28 Dec 2022 20:58:59 +0200 Subject: [PATCH 1/4] add e2e test for envs apps API --- e2e/harmony/app.e2e.ts | 78 ++++++++++++++++++++++++---- src/e2e-helper/e2e-command-helper.ts | 3 ++ src/e2e-helper/e2e-fs-helper.ts | 8 +++ 3 files changed, 79 insertions(+), 10 deletions(-) diff --git a/e2e/harmony/app.e2e.ts b/e2e/harmony/app.e2e.ts index 2327dfa02def..1b36a41b8fbc 100644 --- a/e2e/harmony/app.e2e.ts +++ b/e2e/harmony/app.e2e.ts @@ -1,8 +1,39 @@ import chai, { expect } from 'chai'; +import { join } from 'path'; import Helper from '../../src/e2e-helper/e2e-helper'; chai.use(require('chai-fs')); +const ENV_POLICY = { + peers: [ + { + name: 'react', + version: '^18.0.0', + supportedRange: '^17.0.0 || ^18.0.0', + }, + { + name: 'react-dom', + version: '^18.0.0', + supportedRange: '^17.0.0 || ^18.0.0', + }, + { + name: 'graphql', + version: '14.7.0', + supportedRange: '^14.7.0', + }, + { + name: '@mdx-js/react', + version: '1.6.22', + supportedRange: '^1.6.22', + }, + { + name: '@teambit/mdx.ui.mdx-scope-context', + version: '0.0.496', + supportedRange: '^0.0.496', + }, + ], +}; + describe('app command', function () { this.timeout(0); let helper: Helper; @@ -13,17 +44,44 @@ describe('app command', function () { helper.scopeHelper.destroy(); }); describe('app run', () => { - before(() => { - helper.scopeHelper.setNewLocalAndRemoteScopes({ addRemoteScopeAsDefaultScope: false }); - helper.command.create('express-app', 'my-app'); - helper.command.compile(); - helper.command.install(); - helper.bitJsonc.addKeyVal('my-scope/my-app', {}); + describe('core express app', () => { + before(() => { + helper.scopeHelper.setNewLocalAndRemoteScopes({ addRemoteScopeAsDefaultScope: false }); + helper.command.create('express-app', 'my-app'); + helper.command.compile(); + helper.command.install(); + helper.bitJsonc.addKeyVal('my-scope/my-app', {}); + }); + // previously, it was supporting only app-name + it('should support app-id', () => { + const output = helper.general.runWithTryCatch('bit app run my-scope/my-app'); + expect(output).to.have.string('my-scope/my-app app is running on'); + }); }); - // previously, it was supporting only app-name - it('should support app-id', () => { - const output = helper.general.runWithTryCatch('bit app run my-scope/my-app'); - expect(output).to.have.string('my-scope/my-app app is running on'); + describe.only('env apps API', () => { + describe('React app', () => { + before(() => { + helper.scopeHelper.setNewLocalAndRemoteScopes({ addRemoteScopeAsDefaultScope: false }); + const envId = 'my-scope/react-based-env'; + // Replace with new app template of the new react env when it's ready + helper.command.create('react-app', 'my-app'); + helper.fs.changeFileName(join('my-scope', 'my-app','my-app.react-app.ts'), join('my-scope', 'my-app', 'my-app.react-18-app.ts')) + helper.env.setCustomNewEnv(undefined, undefined, { policy: ENV_POLICY }); + helper.command.setEnv('my-app', envId); + helper.command.install(); + helper.bitJsonc.addKeyVal('my-scope/my-app', {}); + helper.bitJsonc.addKeyVal('teambit.harmony/application', {envs: [envId]}); + }); + it('should show the app', () => { + const output = helper.command.listApps(); + expect(output).to.have.string('my-app'); + expect(output).to.have.string('my-scope/my-app'); + }); + it('should run the app', () => { + const output = helper.command.runApp('my-app'); + expect(output).to.have.string('my-scope/my-app app is running on'); + }); + }); }); }); }); diff --git a/src/e2e-helper/e2e-command-helper.ts b/src/e2e-helper/e2e-command-helper.ts index 2191c7909f58..45ad3eceb0ab 100644 --- a/src/e2e-helper/e2e-command-helper.ts +++ b/src/e2e-helper/e2e-command-helper.ts @@ -655,6 +655,9 @@ export default class CommandHelper { new(templateName: string, flags = '', workspaceName = 'my-workspace', cwd = this.scopes.localPath) { return this.runCmd(`bit new ${templateName} ${workspaceName} ${flags}`, cwd); } + listApps() { + return this.runCmd('bit app list'); + } runApp(name: string) { return this.runCmd(`bit app run ${name}`); } diff --git a/src/e2e-helper/e2e-fs-helper.ts b/src/e2e-helper/e2e-fs-helper.ts index 89710e9c86e9..d7199a8077b5 100644 --- a/src/e2e-helper/e2e-fs-helper.ts +++ b/src/e2e-helper/e2e-fs-helper.ts @@ -91,6 +91,14 @@ export default class FsHelper { fs.outputFileSync(absPath, `\n${content}`); } + changeFileName(filePath: string, newFilePath: string, basePath = this.scopes.localPath) { + const absPath = basePath ? path.join(basePath, filePath) : filePath; + const absNewPath = basePath ? path.join(basePath, newFilePath) : newFilePath; + const content = fs.readFileSync(absPath); + fs.outputFileSync(absNewPath, content); + fs.removeSync(absPath); + } + deletePath(relativePathToLocalScope: string) { return fs.removeSync(path.join(this.scopes.localPath, relativePathToLocalScope)); } From 12044f2adae6e72d8a37c6679cf6f7dcf36fd843 Mon Sep 17 00:00:00 2001 From: Gilad Shoham Date: Sun, 1 Jan 2023 12:52:33 +0200 Subject: [PATCH 2/4] fix tests --- e2e/harmony/app.e2e.ts | 14 ++++++++++++-- src/e2e-helper/e2e-env-helper.ts | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/e2e/harmony/app.e2e.ts b/e2e/harmony/app.e2e.ts index 1b36a41b8fbc..b6b5788cc27d 100644 --- a/e2e/harmony/app.e2e.ts +++ b/e2e/harmony/app.e2e.ts @@ -34,6 +34,15 @@ const ENV_POLICY = { ], }; +export const REACT_CJS_APP = `module.exports.default = { + name: 'my-app', + entry: [require.resolve('./my-app.app-root')], + prerender: { + routes: ['/'] + } +}; +` + describe('app command', function () { this.timeout(0); let helper: Helper; @@ -58,14 +67,15 @@ describe('app command', function () { expect(output).to.have.string('my-scope/my-app app is running on'); }); }); - describe.only('env apps API', () => { + describe('env apps API', () => { describe('React app', () => { before(() => { helper.scopeHelper.setNewLocalAndRemoteScopes({ addRemoteScopeAsDefaultScope: false }); const envId = 'my-scope/react-based-env'; // Replace with new app template of the new react env when it's ready helper.command.create('react-app', 'my-app'); - helper.fs.changeFileName(join('my-scope', 'my-app','my-app.react-app.ts'), join('my-scope', 'my-app', 'my-app.react-18-app.ts')) + helper.fs.writeFile(join('my-scope', 'my-app', 'my-app.react-18-app.cjs'), REACT_CJS_APP); + helper.fs.deletePath(join('my-scope', 'my-app','my-app.react-app.ts')) helper.env.setCustomNewEnv(undefined, undefined, { policy: ENV_POLICY }); helper.command.setEnv('my-app', envId); helper.command.install(); diff --git a/src/e2e-helper/e2e-env-helper.ts b/src/e2e-helper/e2e-env-helper.ts index 5d20e9f4cd52..cfc35fa954ef 100644 --- a/src/e2e-helper/e2e-env-helper.ts +++ b/src/e2e-helper/e2e-env-helper.ts @@ -240,7 +240,8 @@ export default class EnvHelper { * @param extensionsBaseFolder * @returns */ - setCustomNewEnv(extensionsBaseFolder = 'react-based-env', basePackages: string[] = ['@teambit/react.react-env'], envJsoncOptions: GenerateEnvJsoncOptions): string { + // TODO: remove the 0.0.22 version from here. it's here becasue of temporary issue with the regsitry that bring v0.0.20 when no specific version is specified + setCustomNewEnv(extensionsBaseFolder = 'react-based-env', basePackages: string[] = ['@teambit/react.react-env@0.0.22'], envJsoncOptions: GenerateEnvJsoncOptions): string { this.fixtures.copyFixtureExtensions(extensionsBaseFolder); this.command.addComponent(extensionsBaseFolder); this.fixtures.generateEnvJsoncFile(extensionsBaseFolder, envJsoncOptions); From cfa6234bf178b786b260e6c2d11aaa696213dd8c Mon Sep 17 00:00:00 2001 From: Gilad Shoham Date: Sun, 1 Jan 2023 12:56:09 +0200 Subject: [PATCH 3/4] fixes --- e2e/harmony/app.e2e.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/harmony/app.e2e.ts b/e2e/harmony/app.e2e.ts index b6b5788cc27d..0529e26fb707 100644 --- a/e2e/harmony/app.e2e.ts +++ b/e2e/harmony/app.e2e.ts @@ -78,7 +78,7 @@ describe('app command', function () { helper.fs.deletePath(join('my-scope', 'my-app','my-app.react-app.ts')) helper.env.setCustomNewEnv(undefined, undefined, { policy: ENV_POLICY }); helper.command.setEnv('my-app', envId); - helper.command.install(); + helper.command.install('react-router-dom@6.4.3'); helper.bitJsonc.addKeyVal('my-scope/my-app', {}); helper.bitJsonc.addKeyVal('teambit.harmony/application', {envs: [envId]}); }); From 5402939b1fd031d7623e4f0f71db08e2a0628be7 Mon Sep 17 00:00:00 2001 From: Gilad Shoham Date: Mon, 2 Jan 2023 12:06:26 +0200 Subject: [PATCH 4/4] fixes --- e2e/harmony/app.e2e.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/harmony/app.e2e.ts b/e2e/harmony/app.e2e.ts index 0529e26fb707..1e0bc794db11 100644 --- a/e2e/harmony/app.e2e.ts +++ b/e2e/harmony/app.e2e.ts @@ -88,8 +88,8 @@ describe('app command', function () { expect(output).to.have.string('my-scope/my-app'); }); it('should run the app', () => { - const output = helper.command.runApp('my-app'); - expect(output).to.have.string('my-scope/my-app app is running on'); + const output = helper.general.runWithTryCatch('bit app run my-app'); + expect(output).to.have.string('my-app app is running on'); }); }); });