Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove vm2 to run analyses #54

Merged
merged 15 commits into from
Jul 31, 2023
Merged
2 changes: 2 additions & 0 deletions .envfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GREENFRAME_MY_VAR_ONE=envfile_value_one
GREENFRAME_MY_VAR_TWO=envfile_value_two
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@
"unicorn/prefer-module": "off",
// Skipped for now
"unicorn/no-array-for-each": "off",
"unicorn/expiring-todo-comments": "off",
"array-callback-return": "off",
"unicorn/no-new-array": "off",
"unicorn/consistent-function-scoping": "off",
"unicorn/prefer-top-level-await": "off",
"no-promise-executor-return": "off",
"node/no-extraneous-require": "off",
"node/no-extraneous-require": "off"
}
}
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ GreenFrame uses [PlayWright](https://playwright.dev/) to run scenarios. A custom

```js
// in my-scenario.js
async (page) => {
const scenario = async (page) => {
await page.goto('', { waitUntil: 'networkidle' }); // Go to the baseUrl
await page.waitForTimeout(3000); // Wait for 3 seconds
await page.scrollToElement('footer'); // Scroll to the footer (if present)
await page.waitForNetworkIdle(); // Wait every request has been answered as a normal user.
};

module.exports = scenario;
```

Check [the PlayWright documentation on writing tests](https://playwright.dev/docs/writing-tests) for more information.
Expand Down Expand Up @@ -243,21 +245,23 @@ Create an analysis on GreenFrame server.
```
USAGE
$ greenframe analyze [BASEURL] [SCENARIO] [-C <value>] [-K <value>] [-t <value>] [-p <value>] [-c <value>]
[--commitId <value>] [-b <value>] [-s <value>] [-d] [-a] [-i] [--locale] [--timezoneId] [--dockerdHost <value>]
[--dockerdPort <value>] [--containers <value>] [--databaseContainers <value>] [--kubeContainers <value>]
[--kubeDatabaseContainers <value>]
[--commitId <value>] [-b <value>] [-s <value>] [-d] [-a] [-i] [--locale] [--timezoneId] [-e <value>] [-E <value>]
[--dockerdHost <value>] [--dockerdPort <value>] [--containers <value>] [--databaseContainers <value>]
[--kubeContainers <value>] [--kubeDatabaseContainers <value>]

ARGUMENTS
BASEURL Your baseURL website
SCENARIO Path to your GreenFrame scenario

FLAGS
-C, --configFile=<value> Path to config file
-E, --customEnvVarsFile=<value> File of environment vars
-K, --kubeConfig=<value> Path to kubernetes client config file
-a, --useAdblock Use an adblocker during analysis
-b, --branchName=<value> Pass branch name manually
-c, --commitMessage=<value> Pass commit message manually
-d, --distant Run a distant analysis on GreenFrame Server instead of locally
-e, --customEnvVars=<value>... List of environment vars to read in the scenarios
-i, --ignoreHTTPSErrors Ignore HTTPS errors during analysis
-p, --projectName=<value> Project name
-s, --samples=<value> Number of runs done for the score computation
Expand Down Expand Up @@ -293,9 +297,7 @@ FLAGS

DESCRIPTION
Configure kubernetes cluster to collect greenframe metrics

...

greenframe kube-config
```

Expand All @@ -322,9 +324,7 @@ FLAGS

DESCRIPTION
Open browser to develop your GreenFrame scenario

...

greenframe analyze ./yourScenario.js https://greenframe.io
```

Expand All @@ -343,9 +343,7 @@ ARGUMENTS

DESCRIPTION
Update GreenFrame to the latest version

...

greenframe update
```

Expand Down
2 changes: 1 addition & 1 deletion e2e/.greenframe.fullstack.broken.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scenario: '../src/examples/greenframe.js'
scenario: '../../src/examples/greenframe.js'
baseURL: 'https://greenframe.io'
samples: 2
distant: false
Expand Down
2 changes: 1 addition & 1 deletion e2e/.greenframe.single.adblock.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scenario: '../src/examples/greenframe.js'
scenario: '../../src/examples/greenframe.js'
baseURL: 'https://greenframe.io'
samples: 2
projectName: 'GreenFrame'
Expand Down
2 changes: 1 addition & 1 deletion e2e/.greenframe.single.en.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scenario: '../src/examples/marmelab.en.js'
scenario: '../../src/examples/marmelab.en.js'
baseURL: 'https://marmelab.com'
samples: 2
projectName: 'Marmelab'
Expand Down
2 changes: 1 addition & 1 deletion e2e/.greenframe.single.fr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scenario: '../src/examples/marmelab.fr.js'
scenario: '../../src/examples/marmelab.fr.js'
baseURL: 'https://marmelab.com'
samples: 2
projectName: 'Marmelab'
Expand Down
28 changes: 28 additions & 0 deletions e2e/greenframe.io/analyze.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,34 @@ describe.skip('[GREENFRAME.IO] greenframe analyze', () => {
expect(stdout).toContain('✅ main scenario completed');
});

it('should work with env vars inline command', async () => {
const { stdout } = await exec(
`GREENFRAME_MY_VAR_ONE=inline_value_one GREENFRAME_MY_VAR_TWO=inline_value_two ${BASE_COMMAND} https://www.google.fr ../../src/examples/envvar.inline.isolated.js -e GREENFRAME_MY_VAR_ONE -e GREENFRAME_MY_VAR_TWO`
);
expect(stdout).toContain('✅ main scenario completed');
});

it('should work with env file inline command', async () => {
const { stdout } = await exec(
`${BASE_COMMAND} https://www.google.fr ../../src/examples/envvar.inline.envfile.js -E ./src/examples/.envfile`
);
expect(stdout).toContain('✅ main scenario completed');
});

it('should work with env vars and config file', async () => {
const { stdout } = await exec(
`GREENFRAME_MY_VAR_ONE=inline_value_one GREENFRAME_MY_VAR_TWO=inline_value_two ${BASE_COMMAND} https://www.google.fr -C ../../src/examples/envvar.config.isolated.yml`
);
expect(stdout).toContain('✅ main scenario completed');
});

it('should work with env file and config file', async () => {
const { stdout } = await exec(
`${BASE_COMMAND} https://www.google.fr -C ../../src/examples/envvar.config.envfile.yml`
);
expect(stdout).toContain('✅ main scenario completed');
});

it('should set greenframe browser locale right', async () => {
const { stdout: enStdout } = await exec(
`${BASE_COMMAND} -C ./e2e/.greenframe.single.en.yml`
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "greenframe-cli",
"description": "Official GreenFrame CLI",
"version": "1.6.8",
"version": "1.7.0",
"author": "Marmelab",
"bin": {
"greenframe": "./bin/run"
Expand All @@ -11,6 +11,7 @@
"@cliqz/adblocker-playwright": "^1.25.0",
"@kubernetes/client-node": "^0.17.0",
"@oclif/core": "^1.2.0",
"@playwright/test": "^1.30.0",
"@sentry/node": "^6.13.3",
"axios": "^0.22.0",
"core-js-pure": "^3.24.0",
Expand All @@ -22,8 +23,7 @@
"mathjs": "^9.5.0",
"minimist": "^1.2.5",
"oclif": "^2.4.3",
"playwright": "1.30.0",
"vm2": "3.9.16"
"playwright": "1.30.0"
Nitix marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@aws-sdk/client-s3": "^3.36.0",
Expand Down Expand Up @@ -120,6 +120,7 @@
"version": "oclif readme && git add README.md",
"pack": "oclif pack tarballs",
"analyze": "API_URL=http://localhost:3006 APP_URL=http://localhost:3003 ./bin/run analyze",
"open": "API_URL=http://localhost:3006 APP_URL=http://localhost:3003 ./bin/run open",
"upload-installation-scripts": "node ./scripts/uploadInstallScript.js",
"lint": "eslint .",
"typecheck": "tsc --noEmit --pretty"
Expand Down
11 changes: 11 additions & 0 deletions src/commands/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ class AnalyzeCommand extends Command {
timezoneId: Flags.boolean({
description: 'Set greenframe browser timezoneId',
}),
envVar: Flags.string({
char: 'e',
description: 'List of environment vars to read in the scenarios',
required: false,
multiple: true,
}),
envFile: Flags.string({
char: 'E',
description: 'File of environment vars',
required: false,
}),
dockerdHost: Flags.string({
description: 'Docker daemon host',
}),
Expand Down
5 changes: 3 additions & 2 deletions src/commands/open.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { Command, Flags } = require('@oclif/core');
const path = require('node:path');

const { readFileToString } = require('../services/readFileToString');
const { parseConfigFile, resolveParams } = require('../services/parseConfigFile');

const executeScenario = require('../runner/scenarioWrapper.js');
Expand Down Expand Up @@ -63,7 +63,8 @@ class OpenCommand extends Command {
console.info(`Running ${args.scenarios.length} scenarios...`);
for (let index = 0; index < args.scenarios.length; index++) {
const scenario = args.scenarios[index];
const scenarioFile = await readFileToString(configFilePath, scenario.path);
const scenarioPath = path.resolve(scenario.path);
const scenarioFile = require(scenarioPath);
try {
const { timelines } = await executeScenario(scenarioFile, {
debug: true,
Expand Down
2 changes: 2 additions & 0 deletions src/examples/.envfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GREENFRAME_MY_VAR_ONE=envfile_value_one
GREENFRAME_MY_VAR_TWO=envfile_value_two
7 changes: 7 additions & 0 deletions src/examples/commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GREENFRAME_MY_VAR_ONE=inline_value_one greenframe analyze https://www.google.fr ../../src/examples/envvar.inline.isolated.js -e GREENFRAME_MY_VAR_ONE -e GREENFRAME_MY_VAR_TWO=${GREENFRAME_MY_VAR_TWO}

greenframe analyze https://www.google.fr ../../src/examples/envvar.inline.envfile.js -E ./src/examples/.envfile

GREENFRAME_MY_VAR_ONE=inline_value_one greenframe analyze -C ./src/examples/envvar.config.isolated.yml

greenframe analyze -C ./src/examples/envvar.config.envfile.yml
14 changes: 14 additions & 0 deletions src/examples/envvar.config.envfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { expect } = require('@playwright/test');
const myVar1 = process.env.GREENFRAME_MY_VAR_ONE;
const myVar2 = process.env.GREENFRAME_MY_VAR_TWO;

const visit = async (page) => {
expect(myVar1).toBe('envfile_value_one');
expect(myVar2).toBe('envfile_value_two');
await page.goto('', {
waitUntil: 'networkidle',
});
await page.scrollToEnd();
};

module.exports = visit;
7 changes: 7 additions & 0 deletions src/examples/envvar.config.envfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
scenarios:
- path: '../../src/examples/envvar.config.envfile.js'
name: 'Visit'
threshold: 0.03
baseURL: 'https://www.google.fr'
envFile: './src/examples/.envfile'
projectName: 'test_visit'
14 changes: 14 additions & 0 deletions src/examples/envvar.config.isolated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { expect } = require('@playwright/test');
const myVar1 = process.env.GREENFRAME_MY_VAR_ONE;
const myVar2 = process.env.GREENFRAME_MY_VAR_TWO;

const visit = async (page) => {
expect(myVar1).toBe('inline_value_one');
expect(myVar2).toBe('defined_value_two');
await page.goto('', {
waitUntil: 'networkidle',
});
await page.scrollToEnd();
};

module.exports = visit;
9 changes: 9 additions & 0 deletions src/examples/envvar.config.isolated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
scenarios:
- path: '../../src/examples/envvar.config.isolated.js'
name: 'Visit'
threshold: 0.03
baseURL: 'https://www.google.fr'
envVar:
- GREENFRAME_MY_VAR_ONE
- GREENFRAME_MY_VAR_TWO=${GREENFRAME_MY_VAR_TWO}
projectName: 'test_visit'
14 changes: 14 additions & 0 deletions src/examples/envvar.inline.envfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { expect } = require('@playwright/test');
const myVar1 = process.env.GREENFRAME_MY_VAR_ONE;
const myVar2 = process.env.GREENFRAME_MY_VAR_TWO;

const visit = async (page) => {
expect(myVar1).toBe('envfile_value_one');
expect(myVar2).toBe('envfile_value_two');
await page.goto('', {
waitUntil: 'networkidle',
});
await page.scrollToEnd();
};

module.exports = visit;
14 changes: 14 additions & 0 deletions src/examples/envvar.inline.isolated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { expect } = require('@playwright/test');
const myVar1 = process.env.GREENFRAME_MY_VAR_ONE;
const myVar2 = process.env.GREENFRAME_MY_VAR_TWO;

const visit = async (page) => {
expect(myVar1).toBe('inline_value_one');
expect(myVar2).toBe('defined_value_two');
await page.goto('', {
waitUntil: 'networkidle',
});
await page.scrollToEnd();
};

module.exports = visit;
4 changes: 3 additions & 1 deletion src/examples/exampleOfScenario.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
async (page) => {
const example = async (page) => {
await page.goto('', {
waitUntil: 'networkidle',
});
await page.scrollToElement('footer');
};

module.exports = example;
4 changes: 3 additions & 1 deletion src/examples/greenframe.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
async (page) => {
const greenframe = async (page) => {
await page.goto('', {
waitUntil: 'networkidle',
});
Expand All @@ -16,3 +16,5 @@ async (page) => {
waitUntil: 'networkidle',
});
};

module.exports = greenframe;
4 changes: 3 additions & 1 deletion src/examples/greenframe2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
async (page) => {
const greenframe2 = async (page) => {
await page.addMilestone('Go onepage');
await page.goto('/onepage', {
waitUntil: 'networkidle',
});
await page.waitForTimeout(2000);
};

module.exports = greenframe2;
4 changes: 3 additions & 1 deletion src/examples/greenframeFail.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
async (page) => {
const greenframeFail = async (page) => {
await page.goto('', {
waitUntil: 'networkidle',
});
Expand All @@ -16,3 +16,5 @@ async (page) => {
waitUntil: 'networkidle',
});
};

module.exports = greenframeFail;
4 changes: 3 additions & 1 deletion src/examples/laneuvelotte.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
async (page) => {
const laneuvelotte = async (page) => {
await page.goto('', {
waitUntil: 'networkidle',
});
Expand All @@ -22,3 +22,5 @@ async (page) => {
page.click('text=Voir tous les articles par Yann GENSOLLEN'),
]);
};

module.exports = laneuvelotte;
4 changes: 3 additions & 1 deletion src/examples/lavolpiliere.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
async (page) => {
const lavolpiliere = async (page) => {
// Go to https://la-volpiliere.com/blog/chambre-dhotes/
await page.goto('/blog/chambre-dhotes/', {
waitUntil: 'networkidle',
Expand All @@ -18,3 +18,5 @@ async (page) => {
]);
// assert.equal(page.url(), 'https://la-volpiliere.com/blog/1ere-balade-de-lannee-2021/');
};

module.exports = lavolpiliere;
4 changes: 3 additions & 1 deletion src/examples/marmelab.en.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
async (page) => {
const marmelabEN = async (page) => {
await page.goto('', {
waitUntil: 'networkidle',
});
await page.scrollToElement("text=LET'S WORK TOGETHER ON YOUR NEXT PROJECT!");
};

module.exports = marmelabEN;
Loading
Loading