Skip to content

Commit

Permalink
Make integration tests a pakcage
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacov committed Jul 21, 2019
1 parent 8676ea6 commit affe646
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 10 deletions.
14 changes: 14 additions & 0 deletions frontend/integration-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@console/integration-tests",
"version": "0.0.0-fixed",
"description": "Console integration tests",
"private": true,
"devDependencies": {
"protractor": "5.4.x",
"protractor-fail-fast": "3.x",
"protractor-jasmine2-screenshot-reporter": "0.5.x",
"js-yaml": "^3.13.1",
"lodash-es": "4.x",
"immutable": "3.x"
}
}
3 changes: 3 additions & 0 deletions frontend/integration-tests/protractor.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as ConsoleReporter from 'jasmine-console-reporter';
import * as failFast from 'protractor-fail-fast';
import { createWriteStream } from 'fs';
import { format } from 'util';
import { pluginsIntegrationTests } from '@console/plugin-sdk/src/codegen';

const tap = !!process.env.TAP;

Expand All @@ -19,6 +20,7 @@ const junitReporter = new JUnitXmlReporter({ savePath: './gui_test_screenshots',
const browserLogs: logging.Entry[] = [];

const suite = (tests: string[]) => (!_.isNil(process.env.BRIDGE_KUBEADMIN_PASSWORD) ? ['tests/login.scenario.ts'] : []).concat(['tests/base.scenario.ts', ...tests]);
const pluginSuites = pluginsIntegrationTests();

export const config: Config = {
framework: 'jasmine',
Expand Down Expand Up @@ -87,6 +89,7 @@ export const config: Config = {
return new Promise(resolve => htmlReporter.afterLaunch(resolve.bind(this, exitCode)));
},
suites: {
...pluginSuites,
filter: suite([
'tests/filter.scenario.ts',
]),
Expand Down
4 changes: 2 additions & 2 deletions frontend/integration-tests/tests/login.scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('Auth test', () => {

it('logs out htpasswd user', async() => {
await loginView.logout();
expect(browser.getCurrentUrl()).toContain('oauth-openshift');
expect(browser.getCurrentUrl()).toContain('openshift');
expect($('.login-pf').isPresent()).toBeTruthy();
});

Expand All @@ -79,7 +79,7 @@ describe('Auth test', () => {

it('logs out kubeadmin user', async() => {
await loginView.logout();
expect(browser.getCurrentUrl()).toContain('oauth-openshift');
expect(browser.getCurrentUrl()).toContain('openshift');
expect($('.login-pf').isPresent()).toBeTruthy();

// Log back in so that remaining tests can be run
Expand Down
6 changes: 2 additions & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"private": true,
"workspaces": [
"packages/*",
"public"
"public",
"integration-tests"
],
"scripts": {
"clean": "rm -rf ./public/dist",
Expand Down Expand Up @@ -165,9 +166,6 @@
"jest-cli": "21.x",
"mini-css-extract-plugin": "0.4.x",
"node-sass": "4.8.x",
"protractor": "5.4.x",
"protractor-fail-fast": "3.x",
"protractor-jasmine2-screenshot-reporter": "0.5.x",
"read-pkg": "5.x",
"redux-mock-store": "^1.5.3",
"resolve-url-loader": "2.x",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { browser, ExpectedConditions as until, $, $$ } from 'protractor';
import { appHost, testName } from '@console/integration-tests/protractor.conf';
import * as crudView from '@console/integration-tests/views/crud.view';

const BROWSER_TIMEOUT = 15000;

describe('Demo integration test', () => {
it(`Test namespace ${testName}`, async () => {
// Use projects if OpenShift so non-admin users can run tests.
const resource = browser.params.openshift === 'true' ? 'projects' : 'namespaces';
await browser.get(`${appHost}/k8s/cluster/${resource}`);
await crudView.isLoaded();
const exists = await crudView.rowForName(testName).isPresent();

expect(browser.getCurrentUrl()).toContain(appHost);
});
});
14 changes: 12 additions & 2 deletions frontend/packages/console-demo-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
{
"name": "@console/demo-plugin",
"name": "@console/console-demo-plugin",
"version": "0.0.0-fixed",
"description": "Demo plugin for Console web application",
"private": true,
"dependencies": {
"@console/plugin-sdk": "0.0.0-fixed",
"@console/shared": "0.0.0-fixed"
},
"devDependencies": {
"@console/integration-tests": "0.0.0-fixed"
},
"consolePlugin": {
"entry": "src/plugin.tsx"
"entry": "src/plugin.tsx",
"integrationTests": {
"demo": [
"@console/integration-tests/tests/login.scenario.ts",
"@console/integration-tests/tests/base.scenario.ts",
"integration-tests/tests/demo.scenario.ts"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { PluginPackage, Package, filterActivePluginPackages } from '../plugin-resolver';
import { pluginsIntegrationTests } from '../plugin-integration-tests';
import { templatePackage } from './plugin-resolver.spec';

describe('pluginsIntegrationTests', () => {
it('returns a map of short-plugin-name to a list of its integration tests.', () => {
const appPackage: Package = {
...templatePackage,
name: 'app',
dependencies: {
'@console/bar-plugin': '1.2.3',
'@console/qux-plugin': '2.3.4',
},
};

const pluginPackages: PluginPackage[] = [
{
...templatePackage,
name: '@console/bar-plugin',
version: '1.2.3',
consolePlugin: {
entry: 'plugin.ts',
integrationTests: {
bar: [
'@console/integration-tests/tests/base.scenario.ts',
'integration-tests/tests/index.scenario.ts',
],
},
},
},
{
...templatePackage,
name: '@console/qux-plugin',
version: '2.3.4',
consolePlugin: { entry: 'plugin.ts' },
},
];

const pluginFilter = () => filterActivePluginPackages(appPackage, pluginPackages);

const monorepoRootDir = process.cwd();
const expectedTests = {
bar: [
'tests/base.scenario.ts',
`${monorepoRootDir}/packages/bar-plugin/integration-tests/tests/index.scenario.ts`,
],
};

expect(pluginsIntegrationTests(monorepoRootDir, pluginFilter)).toEqual(expectedTests);
});
});
1 change: 1 addition & 0 deletions frontend/packages/console-plugin-sdk/src/codegen/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { resolvePluginPackages } from './plugin-resolver';
export { pluginsIntegrationTests } from './plugin-integration-tests';
export { loadActivePlugins, getActivePluginsModule } from './active-plugins';
export { printPluginStats } from './plugin-stats';
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as _ from 'lodash';
import {
PluginPackage,
filterActivePluginPackages,
PluginPackageFilter,
resolvePluginPackages,
} from './plugin-resolver';

const CONSOLE_PLUGIN_PREFIX = '@console/';
const CONSOLE_INEGRATION_TESTS_PREFIX = '@console/integration-tests/';

/**
* Return a map of short-plugin-name to a list of it's integration tests.
*/
export const pluginsIntegrationTests = (
monorepoRootDir: string = process.cwd(),
pluginFilter: PluginPackageFilter = filterActivePluginPackages,
) => {
const shortName = (plugin: PluginPackage) =>
plugin.name.startsWith(CONSOLE_PLUGIN_PREFIX) && plugin.name.slice(CONSOLE_PLUGIN_PREFIX.length);

const integrationTests = (plugin: PluginPackage) =>
plugin.consolePlugin.integrationTests &&
_.transform(
plugin.consolePlugin.integrationTests,
(result, paths, testName) =>
(result[testName] = _.map(paths, (path) =>
path.startsWith(CONSOLE_INEGRATION_TESTS_PREFIX)
? path.slice(CONSOLE_INEGRATION_TESTS_PREFIX.length)
: `${monorepoRootDir}/packages/${shortName(plugin)}/${path}`,
)),
{},
);

const plugins = resolvePluginPackages(monorepoRootDir, pluginFilter);
const pluginTests = plugins.reduce(
(map, plugin) => Object.assign(map, integrationTests(plugin)),
{},
);

return _.pickBy(pluginTests, (tests) => !!tests);
};
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ export type Package = readPkg.NormalizedPackageJson;
export type PluginPackage = Package & {
consolePlugin: {
entry: string;
integrationTests?: Record<string, string[]>;
};
};

type PluginPackageFilter = (
export type PluginPackageFilter = (
appPackage: Package,
pluginPackages: PluginPackage[],
) => PluginPackage[];
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type Extension<P> = {
*
* ```json
* {
* "name": "@console/demo-plugin",
* "name": "@console/console-demo-plugin",
* "version": "0.0.0-fixed",
* // scripts, dependencies, etc.
* "consolePlugin": {
Expand Down

0 comments on commit affe646

Please sign in to comment.