1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | "use strict";
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | console.log( "[auto-globals] Loading global unit testing tools & utilities... " );
|
20 |
|
21 |
|
22 | let _utils = {
|
23 | env : {},
|
24 | libs : {},
|
25 | paths : {},
|
26 | };
|
27 |
|
28 |
|
29 | global.utils = _utils;
|
30 |
|
31 |
|
32 | if ( process.env.ENDPOINT_TEST_TARGET === undefined ) {
|
33 |
|
34 | throw new Error(
|
35 | "Error in Mocha Test Helper (_mocha-endpoint-test-helper.js): The " +
|
36 | "variable ENDPOINT_TEST_TARGET is required, but was not provided."
|
37 | );
|
38 | }
|
39 |
|
40 | if ( process.env.ENDPOINT_PROJECT_PATH === undefined ) {
|
41 |
|
42 | throw new Error(
|
43 | "Error in Mocha Test Helper (_mocha-endpoint-test-helper.js): The " +
|
44 | "variable ENDPOINT_PROJECT_PATH is required, but was not provided."
|
45 | );
|
46 |
|
47 | } else {
|
48 |
|
49 | _utils.env.endpointProjectPath = process.env.ENDPOINT_PROJECT_PATH;
|
50 | }
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | const EYES = require( "eyes" );
|
57 | const TIPE = require( "tipe" );
|
58 | const LODASH = require( "lodash" );
|
59 | const CHAI = require( "chai" );
|
60 | const BLUEBIRD = require( "bluebird" );
|
61 | const PATH = require( "path" );
|
62 | const EndpointTestHarness = require( "./EndpointTestHarness" );
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | global.expect = CHAI.expect;
|
69 |
|
70 |
|
71 |
|
72 | _utils.libs = {
|
73 | eyes : EYES,
|
74 | tipe : TIPE,
|
75 | lodash : LODASH,
|
76 | chai : CHAI,
|
77 | bluebird : BLUEBIRD,
|
78 | path : PATH,
|
79 | };
|
80 |
|
81 |
|
82 | _utils.paths.project = _utils.env.endpointProjectPath;
|
83 | _utils.paths.projectLib = PATH.join( _utils.paths.project, "lib" );
|
84 | _utils.paths.endpoints = PATH.join( _utils.paths.projectLib, "endpoints" );
|
85 | _utils.paths.models = PATH.join( _utils.paths.projectLib, "models" );
|
86 | _utils.paths.tests = PATH.join( _utils.paths.project, "test" );
|
87 | _utils.paths.coreMS = PATH.join( _utils.paths.project, "node_modules/@corefw/microservices" );
|
88 | _utils.paths.toolsLib = PATH.join( _utils.paths.coreMS, "lib" );
|
89 | _utils.paths.testLib = PATH.join( _utils.paths.toolsLib, "test" );
|
90 |
|
91 |
|
92 | if ( TIPE( process.env.ENDPOINT_TEST_TARGET ) === "string" ) {
|
93 |
|
94 | switch ( process.env.ENDPOINT_TEST_TARGET.toLowerCase() ) {
|
95 |
|
96 | case "local":
|
97 | console.log( "[auto-globals] Found environment variable 'ENDPOINT_TEST_TARGET'..." );
|
98 | console.log( "[auto-globals] ...setting test target to 'local'." );
|
99 | _utils.env.endpointTestTarget = "local";
|
100 | break;
|
101 |
|
102 | case "dev":
|
103 | console.log( "[auto-globals] Found environment variable 'ENDPOINT_TEST_TARGET'..." );
|
104 | console.log( "[auto-globals] ...setting test target to 'dev'." );
|
105 | _utils.env.endpointTestTarget = "dev";
|
106 | break;
|
107 |
|
108 | case "production":
|
109 | console.log( "[auto-globals] Found environment variable 'ENDPOINT_TEST_TARGET'..." );
|
110 | console.log( "[auto-globals] ...setting test target to 'production'." );
|
111 | _utils.env.endpointTestTarget = "production";
|
112 | break;
|
113 |
|
114 | default:
|
115 | console.log( "[auto-globals] Found environment variable 'ENDPOINT_TEST_TARGET'..." );
|
116 | console.log( "[auto-globals] ...but it had an invalid value..." );
|
117 | console.log( "[auto-globals] ...defaulting test target to 'local'." );
|
118 | _utils.env.endpointTestTarget = "local";
|
119 | break;
|
120 | }
|
121 |
|
122 | } else {
|
123 |
|
124 | console.log( "[auto-globals] Environment variable 'ENDPOINT_TEST_TARGET' not found..." );
|
125 | console.log( "[auto-globals] ...defaulting test target to 'local'." );
|
126 | _utils.env.endpointTestTarget = "local";
|
127 | }
|
128 |
|
129 |
|
130 | console.log( " " );
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | _utils.loadYamlFile = function ( absPath, property ) {
|
144 |
|
145 | return EndpointTestHarness.loadYamlFile( absPath, property );
|
146 | };
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 | _utils.createEndpointHarness = function ( cfg ) {
|
163 |
|
164 |
|
165 | if ( TIPE( cfg ) !== "object" ) {
|
166 |
|
167 | cfg = {};
|
168 | }
|
169 |
|
170 |
|
171 | if ( cfg.relEndpointDirectoryPath !== undefined ) {
|
172 |
|
173 | if ( cfg.endpointDirectoryPath === undefined ) {
|
174 |
|
175 |
|
176 | cfg.endpointDirectoryPath = PATH.join(
|
177 | _utils.paths.endpoints,
|
178 | cfg.relEndpointDirectoryPath
|
179 | );
|
180 | }
|
181 |
|
182 |
|
183 | delete cfg.relEndpointDirectoryPath;
|
184 | }
|
185 |
|
186 |
|
187 | if ( cfg.testMode === undefined ) {
|
188 |
|
189 | cfg.testMode = _utils.env.endpointTestTarget;
|
190 | }
|
191 |
|
192 |
|
193 | return new EndpointTestHarness( cfg );
|
194 | };
|