This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
forked from salsify/ember-cli-pact
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
73 lines (60 loc) · 1.94 KB
/
index.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
const commands = require('./lib/commands');
// eslint-disable-next-line node/no-unpublished-require
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = {
name: require('./package').name,
includedCommands() {
return commands;
},
config(env) {
return {
'ember-cli-pact': {
providerName: null,
consumerName: this.project.name(),
mockProvider: 'mirage',
serviceInjections: ['store'],
pactsDirectory: 'pacts',
mode: process.env.PACT_MODE || (process.env.CI ? 'verify' : 'write'),
pactVersion: 3,
enabled: env !== 'production'
}
};
},
treeFor() {
// Most of the addon is in addon-test-support and only included
// in the test environment; however, a few elements are potentially
// used with Mirage, which is enabled in the development environment
// by default and _may_ also be enabled in production (in which case
// the enabled config can be set to true explicitly)
if (this._isEnabled()) {
return this._super.treeFor.apply(this, arguments);
}
},
treeForAddonTestSupport(tree) {
// intentionally not calling _super here
// so that can have our `import`'s be
// import { ... } from 'ember-cli-pact';
const Funnel = require('broccoli-funnel');
let namespacedTree = new Funnel(tree, {
srcDir: '/',
destDir: `/${this.moduleName()}`,
annotation: `Addon#treeForTestSupport (${this.name})`,
});
return this.preprocessJs(namespacedTree, '/', this.name, {
registry: this.registry,
});
},
testemMiddleware(app) {
if (this._isEnabled()) {
const PactMiddleware = require('./lib/pact-middleware');
new PactMiddleware(this._readConfig()).attach(app);
}
},
_isEnabled() {
return this._readConfig().enabled !== false;
},
_readConfig() {
return this.project.config(EmberApp.env())['ember-cli-pact'] || {};
}
};