-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor custom extension (#221)
* chore: refactor custom extension * fix: custom target assertions
- Loading branch information
1 parent
258868d
commit 53ef654
Showing
6 changed files
with
67 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const path = require('path'); | ||
const { BaseExtension } = require("./base.extension"); | ||
const { STATUS, HOOK } = require("../helpers/constants"); | ||
|
||
class CustomExtension extends BaseExtension { | ||
|
||
/** | ||
* @param {import('..').CustomExtension} extension | ||
*/ | ||
constructor(target, extension, result, payload, root_payload) { | ||
super(target, extension, result, payload, root_payload); | ||
this.extension = extension; | ||
this.#setDefaultOptions(); | ||
this.updateExtensionInputs(); | ||
} | ||
|
||
#setDefaultOptions() { | ||
this.default_options.hook = HOOK.END, | ||
this.default_options.condition = STATUS.PASS_OR_FAIL; | ||
} | ||
|
||
async run() { | ||
const params = this.#getParams(); | ||
if (typeof this.extension.inputs.load === 'string') { | ||
const cwd = process.cwd(); | ||
const extension_runner = require(path.join(cwd, this.extension.inputs.load)); | ||
await extension_runner.run(params); | ||
} else if (typeof this.extension.inputs.load === 'function') { | ||
await this.extension.inputs.load(params); | ||
} else { | ||
throw `Invalid 'load' input in custom extension - ${this.extension.inputs.load}`; | ||
} | ||
} | ||
|
||
#getParams() { | ||
return { | ||
target: this.target, | ||
extension: this.extension, | ||
payload: this.payload, | ||
root_payload: this.root_payload, | ||
result: this.result | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports = { CustomExtension } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const p6 = require('pactum'); | ||
const assert = require('assert'); | ||
|
||
async function run({ target, result }) { | ||
assert.equal(target.name, 'custom'); | ||
assert.equal(result.name, 'Default suite'); | ||
await p6.spec().get('http://localhost:9393/custom'); | ||
} | ||
|
||
module.exports = { | ||
run | ||
} |