Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Envs apps api e2e tests #6859

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 78 additions & 10 deletions e2e/harmony/app.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@
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',
},
],
};

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;
Expand All @@ -13,17 +53,45 @@ 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('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.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('[email protected]');
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.general.runWithTryCatch('bit app run my-app');
expect(output).to.have.string('my-app app is running on');
});
});
});
});
});
3 changes: 3 additions & 0 deletions src/e2e-helper/e2e-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/e2e-helper/e2e-env-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]'], envJsoncOptions: GenerateEnvJsoncOptions): string {
this.fixtures.copyFixtureExtensions(extensionsBaseFolder);
this.command.addComponent(extensionsBaseFolder);
this.fixtures.generateEnvJsoncFile(extensionsBaseFolder, envJsoncOptions);
Expand Down
8 changes: 8 additions & 0 deletions src/e2e-helper/e2e-fs-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down