Skip to content

Commit 8c75fab

Browse files
committed
fix: REST test
1 parent 6363989 commit 8c75fab

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

lib/helper/REST.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { default as axios } from 'axios';
22
import Helper from '@codeceptjs/helper';
33
import Secret from '../secret.js';
44
import { beautify } from '../utils.js';
5+
import { output } from '../output.js';
56

67
/**
78
* ## Configuration
@@ -163,20 +164,20 @@ class REST extends Helper {
163164
await this.config.onRequest(request);
164165
}
165166

166-
this.options.prettyPrintJson ? this.debugSection('Request', beautify(JSON.stringify(_debugRequest))) : this.debugSection('Request', JSON.stringify(_debugRequest));
167+
this.options.prettyPrintJson ? output.debugSection('Request', beautify(JSON.stringify(_debugRequest))) : output.debugSection('Request', JSON.stringify(_debugRequest));
167168

168169
let response;
169170
try {
170171
response = await this.axios(request);
171172
} catch (err) {
172173
if (!err.response) throw err;
173-
this.debugSection('Response', `Response error. Status code: ${err.response.status}`);
174+
output.debugSection('Response', `Response error. Status code: ${err.response.status}`);
174175
response = err.response;
175176
}
176177
if (this.config.onResponse) {
177178
await this.config.onResponse(response);
178179
}
179-
this.options.prettyPrintJson ? this.debugSection('Response', beautify(JSON.stringify(response.data))) : this.debugSection('Response', JSON.stringify(response.data));
180+
this.options.prettyPrintJson ? output.debugSection('Response', beautify(JSON.stringify(response.data))) : output.debugSection('Response', JSON.stringify(response.data));
180181
return response;
181182
}
182183

lib/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import deepClone from 'lodash.clonedeep';
66
import merge from 'lodash.merge';
77
import { createHash } from 'crypto';
88
import format from 'js-beautify';
9+
// @ts-ignore
910
import importSync from 'import-sync';
1011
import { convertColorToRGBA, isColorProperty } from './colorUtils.js';
1112

test/helper/MockServer_test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import path from 'path';
1+
import path, { dirname } from 'path';
22

33
import { expect } from 'chai';
44
import { like } from 'pactum-matchers';
5+
import { fileURLToPath } from 'url';
56
import MockServer from '../../lib/helper/MockServer.js';
67
import REST from '../../lib/helper/REST.js';
78

8-
global.codeceptjs = require('../../lib');
9+
global.codeceptjs = '../../lib';
10+
const __dirname = dirname(fileURLToPath(import.meta.url));
911

1012
let I;
1113
let restClient;

0 commit comments

Comments
 (0)