1 | /**
|
2 | * @file Defines the MochaCiExecutionContext class.
|
3 | *
|
4 | * @author Luke Chavers <luke@c2cschools.com>
|
5 | * @author Kevin Sanders <kevin@c2cschools.com>
|
6 | * @since 5.0.0
|
7 | * @license See LICENSE.md for details about licensing.
|
8 | * @copyright 2017 C2C Schools, LLC
|
9 | */
|
10 |
|
11 | ;
|
12 |
|
13 | // Important Note
|
14 | // --------------
|
15 | // This module only loads a single dependency, directly, which is the
|
16 | // parent class for the class defined within. This is intended to force
|
17 | // dependency loading through the parent class, by way of the `$dep()`
|
18 | // method, in order to centralize dependency definition and loading.
|
19 |
|
20 | const BaseMochaExecutionContext = require(
|
21 | "./abstract/BaseMochaExecutionContext"
|
22 | );
|
23 |
|
24 | const ERRORS = require( "../errors" );
|
25 |
|
26 | /**
|
27 | * Represents an execution context whereby an endpoint is executed
|
28 | * in the local environment (of a CI server) by way of Mocha.
|
29 | *
|
30 | * @memberOf ExecutionContext
|
31 | * @extends ExecutionContext.BaseMochaExecutionContext
|
32 | */
|
33 | class MochaCiExecutionContext extends BaseMochaExecutionContext {
|
34 |
|
35 | /**
|
36 | * The name of the current "API Stage" (e.g. "v5", "v5-dev", etc). This
|
37 | * getter extends the default behavior by resolving special stage names
|
38 | * that apply within this execution context (or child contexts).
|
39 | *
|
40 | * @public
|
41 | * @readonly
|
42 | * @type {?string}
|
43 | */
|
44 | get apiStage() {
|
45 |
|
46 | // const me = this;
|
47 |
|
48 | if ( process.env.API_STAGE !== undefined ) {
|
49 |
|
50 | return process.env.API_STAGE;
|
51 |
|
52 | } else if ( process.env.TRAVIS_BRANCH === undefined ) {
|
53 |
|
54 | throw new ERRORS.ContextDataResolutionError(
|
55 | "Couldn't find the TRAVIS_BRANCH environment variable, which " +
|
56 | "is needed for apiStage resolution in MochaCiExecutionContext."
|
57 | );
|
58 |
|
59 | } else if ( process.env.TRAVIS_BRANCH === "develop" ) {
|
60 |
|
61 | return "dev";
|
62 |
|
63 | } else {
|
64 |
|
65 | return process.env.TRAVIS_BRANCH;
|
66 | }
|
67 | }
|
68 |
|
69 | /**
|
70 | * Generates a fake requestId that is prefixed with four 5's.
|
71 | *
|
72 | * @private
|
73 | * @returns {string} A fake request ID.
|
74 | */
|
75 | _createFakeRequestId() {
|
76 |
|
77 | const me = this;
|
78 |
|
79 | // Although we want to generate a valid requestId (for realism),
|
80 | // we're going to set the first block of characters to something
|
81 | // that identifies the UUID as being unusual and, further, as
|
82 | // being generated by this line of execution contexts.
|
83 |
|
84 | // Dependencies
|
85 | const uuidUtils = me.$dep( "util/uuid" );
|
86 |
|
87 | return uuidUtils.generate( "5555" );
|
88 | }
|
89 | }
|
90 |
|
91 | module.exports = MochaCiExecutionContext;
|