All files / test-support execution_context.js

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                                                                                           
import { getContext } from './helpers';
import isRfc268Test from './is-rfc268-test';
import AcceptanceExecutionContext from './execution_context/acceptance';
import IntegrationExecutionContext from './execution_context/integration';
import Rfc268Context from './execution_context/rfc268';
 
const executioncontexts = {
  acceptance: AcceptanceExecutionContext,
  integration: IntegrationExecutionContext,
  rfc268: Rfc268Context
};
 
/*
 * @private
 */
export function getExecutionContext(pageObjectNode) {
  // Our `getContext(pageObjectNode)` will return a context only if the test
  // called `page.setContext(this)`, which is only supposed to happen in
  // integration tests (i.e. pre-RFC232/RFC268). However, the integration
  // context does work with RFC232 (`setupRenderingContext()`) tests, and before
  // the RFC268 execution context was implemented, some users may have migrated
  // their tests to RFC232 tests, leaving the `page.setContext(this)` in place.
  // So, in order to not break those tests, we need to check for that case
  // first, and only if that hasn't happened, check to see if we're in an
  // RFC232/RFC268 test, and if not, fall back on assuming a pre-RFC268
  // acceptance test, which is the only remaining supported scenario.
  let testContext = getContext(pageObjectNode);
  let context;
  if (testContext) {
    context = 'integration';
  } else if (isRfc268Test()) {
    context = 'rfc268';
  } else {
    context = 'acceptance';
  }
 
  return new executioncontexts[context](pageObjectNode, testContext);
}
 
/*
 * @private
 */
export function register(type, definition) {
  executioncontexts[type] = definition;
}