Skip to content

Commit

Permalink
fix(install cmd): use correct env vars for network shim in install co…
Browse files Browse the repository at this point in the history
…mmand (#234)

* fix(install cmd): change "network" env var to "networkMode"

* fix(install cmd): change "serverMinorVersion" env var to "dhis2ApiVersion"

* chore(network-shim): rename serverVersionMinor to apiVersion

Co-authored-by: Hendrik de Graaf <hendrik@dhis2.org>
  • Loading branch information
Mohammer5 and HendrikThePendric authored Jun 10, 2021
1 parent 5426206 commit a91da93
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
10 changes: 5 additions & 5 deletions packages/cli/src/commands/install/enableNetworkShim.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ module.exports.enableNetworkShim = async ({ options, state }) => {

const prompt = inquirer.createPromptModule()

const { serverMinorVersion } = await prompt([
const { dhis2ApiVersion } = await prompt([
{
type: 'input',
name: 'serverMinorVersion',
name: 'dhis2ApiVersion',
message: 'The minor version of the server (e. g. 37)',
default: '',
},
Expand All @@ -20,7 +20,7 @@ module.exports.enableNetworkShim = async ({ options, state }) => {
...state.cypressJson,
env: {
...state.cypressJson.env,
network: 'live',
networkMode: 'live',
},
},
support: [...state.support, 'enableNetworkShim'],
Expand All @@ -33,8 +33,8 @@ module.exports.enableNetworkShim = async ({ options, state }) => {
],
}

if (serverMinorVersion) {
nextState.cypressJson.env.serverMinorVersion = serverMinorVersion
if (dhis2ApiVersion) {
nextState.cypressJson.env.dhis2ApiVersion = dhis2ApiVersion
}

return nextState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ const rimraf = require('rimraf')

module.exports = function clearNetworkFixtures({ fixturesFolder, env }) {
try {
const serverMinorVersion = env.dhis2ApiVersion.toString()
const versionMinorDir = path.join(fixturesFolder, serverMinorVersion)
const apiVersion = env.dhis2ApiVersion.toString()
const versionMinorDir = path.join(fixturesFolder, apiVersion)

if (fs.existsSync(versionMinorDir)) {
rimraf.sync(versionMinorDir)
}

log.info(
`Cleared network fixture directory for version: ${serverMinorVersion}`
)
log.info(`Cleared network fixture directory for version: ${apiVersion}`)
} catch (error) {
throw new Error(
`Encountered an error resetting the network fixtures: ${error.message}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function createFixturesFromState(state, cypressConfig) {
totalResponseSize: state.totalResponseSize,
duplicates: state.duplicates,
nonDeterministicResponses: state.nonDeterministicResponses,
serverMinorVersion: state.config.serverMinorVersion,
apiVersion: state.config.apiVersion,
fixtureFiles: [],
}
const files = state.requestStubs.reduce(
Expand Down
14 changes: 6 additions & 8 deletions packages/cypress-plugins/src/plugins/networkShim/createState.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { isCaptureMode, isStubMode, getFixturesDir } = require('./utils.js')
/**
* Configuration section of the network shim state
* @typedef {Object} NetworkShimConfig
* @property {number} serverMinorVersion DHIS2 Core instance server minor version, i.e. 36
* @property {number} apiVersion DHIS2 Core instance server minor version, i.e. 36
* @property {String[]} hosts List of domains to capture/stub requests for
* @property {String[]} staticResources List of resources not specific to any test and guaranteed to
* always return the same response
Expand Down Expand Up @@ -58,17 +58,17 @@ const { isCaptureMode, isStubMode, getFixturesDir } = require('./utils.js')
module.exports = function createState(cypressConfig, hosts, staticResources) {
try {
const env = cypressConfig.env
const serverMinorVersion = env.dhis2ApiVersion
const apiVersion = env.dhis2ApiVersion
const fixturesDir = getFixturesDir(cypressConfig)
const config = {
serverMinorVersion,
apiVersion,
mode: env.networkMode,
hosts: hosts || [env.dhis2BaseUrl],
staticResources,
}

if (isCaptureMode(env)) {
clearFixturesDir(fixturesDir, serverMinorVersion)
clearFixturesDir(fixturesDir, apiVersion)
return createInitialState(config)
} else if (isStubMode(env)) {
return createStateFromFixtures(config, fixturesDir)
Expand All @@ -80,16 +80,14 @@ module.exports = function createState(cypressConfig, hosts, staticResources) {
}
}

function clearFixturesDir(fixtureDir, serverMinorVersion) {
function clearFixturesDir(fixtureDir, apiVersion) {
try {
if (fs.existsSync(fixtureDir)) {
rimraf.sync(fixtureDir)
}
fs.ensureDirSync(fixtureDir)

log.info(
`Cleared network fixture directory for version: ${serverMinorVersion}`
)
log.info(`Cleared network fixture directory for version: ${apiVersion}`)
} catch (error) {
throw new Error(
`Encountered an error clearing the network fixtures directory: ${error.message}`
Expand Down

0 comments on commit a91da93

Please sign in to comment.