forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@grafana/e2e: added support for plugin repositories (grafana#22546)
* Minor changes * Include Cypress support files in published package * Added CLI … with support for custom configurations (which Cypress does not currently support by default): * Loads cypress.json from @grafana/e2e as a base config (via a custom Cypress plugin) * Sets default values for project-level Cypress files (tests, etc) * Optionally loads a cypress.json from the current working directory as overrides * Updated lockfile
- Loading branch information
1 parent
c3884ab
commit ee5fcc0
Showing
9 changed files
with
289 additions
and
31 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,10 @@ | ||
#!/usr/bin/env node | ||
|
||
// This file is used only for internal executions | ||
|
||
require('ts-node').register({ | ||
project: `${__dirname}/../tsconfig.json`, | ||
transpileOnly: true, | ||
}); | ||
|
||
require('../src/cli/index.ts').default(); |
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,60 @@ | ||
'use strict'; | ||
const { | ||
promises: { readFile }, | ||
} = require('fs'); | ||
const { resolve } = require('path'); | ||
|
||
module.exports = async baseConfig => { | ||
// From CLI | ||
const { | ||
env: { CWD }, | ||
} = baseConfig; | ||
|
||
if (CWD) { | ||
const projectConfig = { | ||
integrationFolder: `${CWD}/cypress/integration`, | ||
screenshotsFolder: `${CWD}/cypress/screenshots`, | ||
videosFolder: `${CWD}/cypress/videos`, | ||
}; | ||
|
||
const customProjectConfig = await readFile(`${CWD}/cypress.json`, 'utf8') | ||
.then(JSON.parse) | ||
.then(config => { | ||
const pathKeys = [ | ||
'fileServerFolder', | ||
'fixturesFolder', | ||
'ignoreTestFiles', | ||
'integrationFolder', | ||
'pluginsFile', | ||
'screenshotsFolder', | ||
'supportFile', | ||
'testFiles', | ||
'videosFolder', | ||
]; | ||
|
||
return Object.fromEntries( | ||
Object.entries(config).map(([key, value]) => { | ||
if (pathKeys.includes(key)) { | ||
return [key, resolve(CWD, value)]; | ||
} else { | ||
return [key, value]; | ||
} | ||
}) | ||
); | ||
}) | ||
.catch(error => { | ||
if (error.code === 'ENOENT') { | ||
// File is optional | ||
return null; | ||
} else { | ||
// Unexpected error | ||
throw error; | ||
} | ||
}); | ||
|
||
return { ...baseConfig, ...projectConfig, ...customProjectConfig }; | ||
} else { | ||
// Temporary legacy support for Grafana core (using `yarn start`) | ||
return baseConfig; | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,33 +1,38 @@ | ||
import resolve from 'rollup-plugin-node-resolve'; | ||
import commonjs from 'rollup-plugin-commonjs'; | ||
import copy from 'rollup-plugin-copy'; | ||
import sourceMaps from 'rollup-plugin-sourcemaps'; | ||
import { terser } from 'rollup-plugin-terser'; | ||
|
||
const pkg = require('./package.json'); | ||
const { name } = require('./package.json'); | ||
|
||
const libraryName = pkg.name; | ||
const buildCjsPackage = ({ env }) => ({ | ||
input: 'compiled/index.js', | ||
output: { | ||
file: `dist/index.${env}.js`, | ||
name, | ||
format: 'cjs', | ||
sourcemap: true, | ||
exports: 'named', | ||
globals: {}, | ||
}, | ||
plugins: [ | ||
copy({ | ||
flatten: false, | ||
targets: [ | ||
{ src: 'compiled/bin/**/*.*', dest: 'dist/' }, | ||
{ src: 'compiled/cli/**/*.*', dest: 'dist/' }, | ||
{ src: 'cypress.json', dest: 'dist/' }, | ||
{ src: 'cypress/**/*.+(js|ts)', dest: 'dist/cypress/' }, | ||
], | ||
}), | ||
commonjs({ | ||
include: /node_modules/, | ||
}), | ||
resolve(), | ||
sourceMaps(), | ||
env === 'production' && terser(), | ||
], | ||
}); | ||
|
||
const buildCjsPackage = ({ env }) => { | ||
return { | ||
input: `compiled/index.js`, | ||
output: [ | ||
{ | ||
file: `dist/index.${env}.js`, | ||
name: libraryName, | ||
format: 'cjs', | ||
sourcemap: true, | ||
exports: 'named', | ||
globals: {}, | ||
}, | ||
], | ||
plugins: [ | ||
commonjs({ | ||
include: /node_modules/, | ||
}), | ||
resolve(), | ||
sourceMaps(), | ||
env === 'production' && terser(), | ||
], | ||
}; | ||
}; | ||
export default [buildCjsPackage({ env: 'development' }), buildCjsPackage({ env: 'production' })]; |
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,5 @@ | ||
#!/usr/bin/env node | ||
|
||
import cli from '../cli/index'; | ||
|
||
cli(); |
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,40 @@ | ||
import { resolve, sep } from 'path'; | ||
import execa, { Options } from 'execa'; | ||
import program from 'commander'; | ||
|
||
const cypress = (commandName: string) => { | ||
// Support running an unpublished dev build | ||
const parentPath = resolve(`${__dirname}/../`); | ||
const parentDirname = parentPath.split(sep).pop(); | ||
const projectPath = resolve(`${parentPath}${parentDirname === 'dist' ? '/..' : ''}`); | ||
|
||
const cypressOptions = [commandName, '--env', `CWD=${process.cwd()}`, `--project=${projectPath}`]; | ||
|
||
const execaOptions: Options = { | ||
cwd: __dirname, | ||
stdio: 'inherit', | ||
}; | ||
|
||
return execa(`${projectPath}/node_modules/.bin/cypress`, cypressOptions, execaOptions) | ||
.then(() => {}) // no return value | ||
.catch(error => console.error(error.message)); | ||
}; | ||
|
||
export default () => { | ||
const configOption = '-c, --config <path>'; | ||
const configDescription = 'path to JSON file where configuration values are set; defaults to "cypress.json"'; | ||
|
||
program | ||
.command('open') | ||
.description('runs tests within the interactive GUI') | ||
.option(configOption, configDescription) | ||
.action(() => cypress('open')); | ||
|
||
program | ||
.command('run') | ||
.description('runs tests from the CLI without the GUI') | ||
.option(configOption, configDescription) | ||
.action(() => cypress('run')); | ||
|
||
program.parse(process.argv); | ||
}; |
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
Oops, something went wrong.