-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use CYPRESS_PACKAGE_CONFIG_PATH
- Loading branch information
Showing
13 changed files
with
495 additions
and
250 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 |
---|---|---|
@@ -1,74 +1,96 @@ | ||
# Logs | ||
|
||
logs | ||
*.log | ||
npm-debug.log* | ||
_.log | ||
npm-debug.log_ | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.vscode/settings.json | ||
|
||
# Runtime data | ||
|
||
pids | ||
*.pid | ||
*.seed | ||
_.pid | ||
_.seed | ||
*.pid.lock | ||
|
||
# dynamic graphql typedefs | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
|
||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
|
||
coverage | ||
|
||
# nyc test coverage | ||
|
||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
|
||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
|
||
bower_components | ||
|
||
# node-waf configuration | ||
|
||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
|
||
build/Release | ||
dist | ||
|
||
# Dependency directories | ||
|
||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
|
||
typings/ | ||
|
||
# Optional npm cache directory | ||
|
||
.npm | ||
|
||
# Optional eslint cache | ||
|
||
.eslintcache | ||
|
||
# Optional REPL history | ||
|
||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
\*.tgz | ||
|
||
# Yarn Integrity file | ||
|
||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
|
||
.env | ||
|
||
# next.js build output | ||
|
||
.next | ||
|
||
# AWS | ||
|
||
credentials | ||
|
||
# Minio | ||
|
||
/data | ||
example/data | ||
|
||
_local | ||
_global | ||
_global | ||
**/__temp_fixture* |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const fs = require('fs'); | ||
const { getConfigFilesPaths } = require('../discovery'); | ||
const { getAutoDiscoveredConfigFilesPaths } = require('../auto-discovery'); | ||
|
||
jest.mock('../auto-discovery'); | ||
|
||
test('should use explicit path', async () => { | ||
fs.statSync = jest.fn().mockReturnValue(true); | ||
|
||
const result = await getConfigFilesPaths('explicitPath/app.yml'); | ||
|
||
expect(result.configFilePath).toMatch('explicitPath/app.yml'); | ||
expect(result.backupConfigFilePath).toMatch('explicitPath/_app.yml'); | ||
expect(fs.statSync).toHaveBeenCalledWith( | ||
expect.stringMatching('explicitPath') | ||
); | ||
}); | ||
|
||
test('should use auto-discovery', async () => { | ||
getAutoDiscoveredConfigFilesPaths.mockReturnValue({}); | ||
|
||
await getConfigFilesPaths(); | ||
|
||
expect(getAutoDiscoveredConfigFilesPaths).toHaveBeenCalled(); | ||
}); |
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,18 @@ | ||
default: | ||
cdn_url: https://cdn.cypress.io | ||
desktop_url: https://download.cypress.io/desktop | ||
desktop_manifest_url: https://download.cypress.io/desktop.json | ||
chromium_url: https://download.cypress.io/chromium | ||
chromium_manifest_url: https://download.cypress.io/chromium.json | ||
development: | ||
api_url: http://localhost:1234/ | ||
on_url: http://localhost:8080/ | ||
test: | ||
api_url: http://localhost:1234/ | ||
on_url: http://localhost:8080/ | ||
staging: | ||
api_url: https://api-staging.cypress.io/ | ||
on_url: https://on.cypress.io/ | ||
production: | ||
api_url: https://api.cypress.io/ | ||
on_url: https://on.cypress.io/ |
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,34 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const yaml = require('js-yaml'); | ||
const { nanoid } = require('nanoid'); | ||
|
||
const { patch } = require('../patch'); | ||
const { getConfigFilesPaths } = require('../discovery'); | ||
|
||
jest.mock('../discovery'); | ||
|
||
const original = path.resolve(__dirname, './fixtures/app.yml'); | ||
|
||
test('should patch', async () => { | ||
const seed = nanoid(); | ||
const filename = `./fixtures/__temp_fixture_${seed}`; | ||
|
||
const configFilePath = path.resolve(__dirname, `${filename}.yml`); | ||
const backupConfigFilePath = path.resolve( | ||
__dirname, | ||
`${filename}_backup.yml` | ||
); | ||
fs.copyFileSync(original, configFilePath); | ||
|
||
getConfigFilesPaths.mockResolvedValueOnce({ | ||
configFilePath, | ||
backupConfigFilePath, | ||
}); | ||
|
||
await patch(seed); | ||
|
||
const doc = yaml.load(fs.readFileSync(configFilePath, 'utf8')); | ||
expect(doc.production.api_url).toEqual(seed); | ||
}); |
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,67 @@ | ||
const path = require('path'); | ||
const { getCypressCLIBinPath } = require('./bin-path'); | ||
const { lookupPaths } = require('./fs'); | ||
const debug = require('debug')('cy2'); | ||
|
||
module.exports = { | ||
getAutoDiscoveredConfigFilesPaths, | ||
}; | ||
|
||
async function getAutoDiscoveredConfigFilesPaths() { | ||
const stateModulePath = await getStateModulePath(); | ||
const state = require(stateModulePath); | ||
|
||
const pkgPath = state.getBinaryPkgPath(state.getBinaryDir()); | ||
debug('Cypress pkgPath: %s', pkgPath); | ||
|
||
const pkgRoot = path.dirname(pkgPath); | ||
debug('Cypress pkgRoot: %s', pkgRoot); | ||
|
||
const configFilePath = path.resolve( | ||
pkgRoot, | ||
'packages/server/config/app.yml' | ||
); | ||
const backupConfigFilePath = path.resolve( | ||
pkgRoot, | ||
'packages/server/config/_app.yml' | ||
); | ||
|
||
debug('Cypress configFilePath: %s', configFilePath); | ||
return { | ||
configFilePath, | ||
backupConfigFilePath, | ||
}; | ||
} | ||
|
||
async function getStateModulePath() { | ||
try { | ||
const cliBinPath = await getCypressCLIBinPath(); | ||
const candidates = [ | ||
path.join( | ||
path.dirname(cliBinPath), | ||
'node_modules', | ||
'cypress/lib/tasks/state.js' | ||
), | ||
path.join(path.dirname(cliBinPath), '..', 'lib/tasks/state.js'), | ||
path.join( | ||
path.dirname(cliBinPath), | ||
'..', | ||
'cypress', | ||
'lib/tasks/state.js' | ||
), | ||
]; | ||
|
||
debug('Cypress state module candidates: %o', candidates); | ||
|
||
const result = lookupPaths(candidates); | ||
|
||
if (!result) { | ||
throw new Error('Cannot detect cypress'); | ||
} | ||
|
||
debug('Cypress state module detected: %s', result); | ||
return result; | ||
} catch (error) { | ||
throw new Error('Cannot detect cypress. Is cypress installed?'); | ||
} | ||
} |
Oops, something went wrong.