Skip to content

Commit 77feb55

Browse files
Merge pull request #75 from marmelab/main
Deploy v2.0.0
2 parents 05a1b60 + c7445be commit 77feb55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4149
-2882
lines changed

.envfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GREENFRAME_MY_VAR_ONE=envfile_value_one
2+
GREENFRAME_MY_VAR_TWO=envfile_value_two

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@
5050
"unicorn/prefer-module": "off",
5151
// Skipped for now
5252
"unicorn/no-array-for-each": "off",
53+
"unicorn/expiring-todo-comments": "off",
5354
"array-callback-return": "off",
5455
"unicorn/no-new-array": "off",
5556
"unicorn/consistent-function-scoping": "off",
5657
"unicorn/prefer-top-level-await": "off",
5758
"no-promise-executor-return": "off",
58-
"node/no-extraneous-require": "off",
59+
"node/no-extraneous-require": "off"
5960
}
6061
}

README.md

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,7 @@ You can run a custom scenario instead of the "visit" scenario by passing a scena
5454
$ greenframe analyze https://marmelab.com ./my-scenario.js
5555
```
5656

57-
GreenFrame uses [PlayWright](https://playwright.dev/) to run scenarios. A custom PlayWright scenario looks like the following:
58-
59-
```js
60-
// in my-scenario.js
61-
async (page) => {
62-
await page.goto('', { waitUntil: 'networkidle' }); // Go to the baseUrl
63-
await page.waitForTimeout(3000); // Wait for 3 seconds
64-
await page.scrollToElement('footer'); // Scroll to the footer (if present)
65-
await page.waitForNetworkIdle(); // Wait every request has been answered as a normal user.
66-
};
67-
```
57+
GreenFrame uses [PlayWright](https://playwright.dev/) to run scenarios. To discover what a custom PlayWright scenario looks alike, you can refer to our [documentation](https://docs.greenframe.io/scenario/).
6858

6959
Check [the PlayWright documentation on writing tests](https://playwright.dev/docs/writing-tests) for more information.
7060

@@ -182,7 +172,7 @@ scenarios:
182172
threshold: 0.1
183173
projectName: YOUR_PROJECT_NAME
184174
samples: 3
185-
distant: false
175+
//distant: "This option has been deprecated due to security issues"
186176
useAdblock: true
187177
ignoreHTTPSErrors: true
188178
locale: 'fr-FR',
@@ -191,7 +181,11 @@ containers:
191181
- 'CONTAINER_NAME'
192182
- 'ANOTHER_CONTAINER_NAME'
193183
databaseContainers:
194-
- 'DATABASE_CONTAINER_NAME'
184+
- 'DATABASE_CONTAINER_NAME',
185+
envFile: PATH_TO_YOUR_ENVIRONMENT_VAR_FILE
186+
envVar:
187+
- envVarA: 'An environment variable needed for the scenario (ie : a secret-key)',
188+
- envVarB: 'Another environment variable needed'
195189
```
196190
197191
## More Information / Troubleshooting
@@ -243,21 +237,22 @@ Create an analysis on GreenFrame server.
243237
```
244238
USAGE
245239
$ greenframe analyze [BASEURL] [SCENARIO] [-C <value>] [-K <value>] [-t <value>] [-p <value>] [-c <value>]
246-
[--commitId <value>] [-b <value>] [-s <value>] [-d] [-a] [-i] [--locale] [--timezoneId] [--dockerdHost <value>]
247-
[--dockerdPort <value>] [--containers <value>] [--databaseContainers <value>] [--kubeContainers <value>]
248-
[--kubeDatabaseContainers <value>]
240+
[--commitId <value>] [-b <value>] [-s <value>] [-a] [-i] [--locale] [--timezoneId] [-e <value>] [-E <value>]
241+
[--dockerdHost <value>] [--dockerdPort <value>] [--containers <value>] [--databaseContainers <value>]
242+
[--kubeContainers <value>] [--kubeDatabaseContainers <value>]
249243

250244
ARGUMENTS
251245
BASEURL Your baseURL website
252246
SCENARIO Path to your GreenFrame scenario
253247

254248
FLAGS
255249
-C, --configFile=<value> Path to config file
250+
-E, --envFile=<value> File of environment vars
256251
-K, --kubeConfig=<value> Path to kubernetes client config file
257252
-a, --useAdblock Use an adblocker during analysis
258253
-b, --branchName=<value> Pass branch name manually
259254
-c, --commitMessage=<value> Pass commit message manually
260-
-d, --distant Run a distant analysis on GreenFrame Server instead of locally
255+
-e, --envVar=<value>... List of environment vars to read in the scenarios
261256
-i, --ignoreHTTPSErrors Ignore HTTPS errors during analysis
262257
-p, --projectName=<value> Project name
263258
-s, --samples=<value> Number of runs done for the score computation
@@ -276,7 +271,7 @@ DESCRIPTION
276271
Create an analysis on GreenFrame server.
277272
```
278273
279-
_See code: [dist/commands/analyze.ts](https://github.com/marmelab/greenframe-cli/blob/v1.6.8/dist/commands/analyze.ts)_
274+
_See code: [dist/commands/analyze.ts](https://github.com/marmelab/greenframe-cli/blob/v1.7.0/dist/commands/analyze.ts)_
280275
281276
## `greenframe kube-config`
282277
@@ -293,13 +288,11 @@ FLAGS
293288

294289
DESCRIPTION
295290
Configure kubernetes cluster to collect greenframe metrics
296-
297291
...
298-
299292
greenframe kube-config
300293
```
301294
302-
_See code: [dist/commands/kube-config.ts](https://github.com/marmelab/greenframe-cli/blob/v1.6.8/dist/commands/kube-config.ts)_
295+
_See code: [dist/commands/kube-config.ts](https://github.com/marmelab/greenframe-cli/blob/v1.7.0/dist/commands/kube-config.ts)_
303296
304297
## `greenframe open [BASEURL] [SCENARIO]`
305298
@@ -322,13 +315,11 @@ FLAGS
322315

323316
DESCRIPTION
324317
Open browser to develop your GreenFrame scenario
325-
326318
...
327-
328319
greenframe analyze ./yourScenario.js https://greenframe.io
329320
```
330321
331-
_See code: [dist/commands/open.ts](https://github.com/marmelab/greenframe-cli/blob/v1.6.8/dist/commands/open.ts)_
322+
_See code: [dist/commands/open.ts](https://github.com/marmelab/greenframe-cli/blob/v1.7.0/dist/commands/open.ts)_
332323
333324
## `greenframe update [CHANNEL]`
334325
@@ -343,13 +334,11 @@ ARGUMENTS
343334

344335
DESCRIPTION
345336
Update GreenFrame to the latest version
346-
347337
...
348-
349338
greenframe update
350339
```
351340
352-
_See code: [dist/commands/update.ts](https://github.com/marmelab/greenframe-cli/blob/v1.6.8/dist/commands/update.ts)_
341+
_See code: [dist/commands/update.ts](https://github.com/marmelab/greenframe-cli/blob/v1.7.0/dist/commands/update.ts)_
353342
<!-- commandsstop -->
354343
355344
## Development

e2e/.greenframe.fullstack.broken.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
scenario: '../src/examples/greenframe.js'
1+
scenario: '../../src/examples/greenframe.js'
22
baseURL: 'https://greenframe.io'
33
samples: 2
4-
distant: false
54
projectName: 'GreenFrame'
65
containers:
76
- 'enterprise_api'

e2e/.greenframe.fullstack.emptyScenario.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
baseURL: 'https://greenframe.io'
22
samples: 2
3-
distant: false
43
projectName: 'GreenFrame'
54
containers:
65
- 'enterprise_api'

e2e/.greenframe.fullstack.k8s.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
scenario: '../src/examples/greenframe.js'
22
baseURL: 'https://greenframe.io'
33
samples: 2
4-
distant: false
54
projectName: 'GreenFrame'
65
kubeContainers:
76
- 'default:app=api'

e2e/.greenframe.fullstack.multiple.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ scenarios:
77
threshold: 0.05
88
baseURL: 'https://greenframe.io'
99
samples: 2
10-
distant: false
1110
projectName: 'GreenFrame'
1211
containers:
1312
- 'enterprise_api'

e2e/.greenframe.fullstack.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
scenario: '../src/examples/greenframe.js'
22
baseURL: 'https://greenframe.io'
33
samples: 2
4-
distant: false
54
projectName: 'GreenFrame'
65
containers:
76
- 'enterprise_api'

e2e/.greenframe.single.adblock.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
scenario: '../src/examples/greenframe.js'
1+
scenario: '../../src/examples/greenframe.js'
22
baseURL: 'https://greenframe.io'
33
samples: 2
44
projectName: 'GreenFrame'
5-
distant: false
65
useAdblock: true

e2e/.greenframe.single.en.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
scenario: '../src/examples/marmelab.en.js'
1+
scenario: '../../src/examples/marmelab.en.js'
22
baseURL: 'https://marmelab.com'
33
samples: 2
44
projectName: 'Marmelab'
5-
distant: false
65
useAdblock: true
76
locale: en-US

e2e/.greenframe.single.fr.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
scenario: '../src/examples/marmelab.fr.js'
1+
scenario: '../../src/examples/marmelab.fr.js'
22
baseURL: 'https://marmelab.com'
33
samples: 2
44
projectName: 'Marmelab'
5-
distant: false
65
useAdblock: true
76
locale: fr-FR

e2e/.greenframe.single.multiple.distant.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ scenarios:
77
threshold: 0.05
88
baseURL: 'https://greenframe.io'
99
samples: 2
10-
distant: true
1110
projectName: 'GreenFrame'

e2e/greenframe.io/analyze.spec.js

Lines changed: 25 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -26,88 +26,51 @@ describe.skip('[GREENFRAME.IO] greenframe analyze', () => {
2626
expect(stdout).toContain('✅ main scenario completed');
2727
});
2828

29-
it('should set greenframe browser locale right', async () => {
30-
const { stdout: enStdout } = await exec(
31-
`${BASE_COMMAND} -C ./e2e/.greenframe.single.en.yml`
32-
);
33-
expect(enStdout).toContain('✅ main scenario completed');
34-
const { stdout: frStdout } = await exec(
35-
`${BASE_COMMAND} -C ./e2e/.greenframe.single.fr.yml`
29+
it('should work with env vars inline command', async () => {
30+
const { stdout } = await exec(
31+
`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`
3632
);
37-
expect(frStdout).toContain('✅ main scenario completed');
33+
expect(stdout).toContain('✅ main scenario completed');
3834
});
3935

40-
it('should run an analysis command with adblocker', async () => {
41-
const { error, stdout } = await exec(
42-
`${BASE_COMMAND} -C ./e2e/.greenframe.adblock.yml`
36+
it('should work with env file inline command', async () => {
37+
const { stdout } = await exec(
38+
`${BASE_COMMAND} https://www.google.fr ../../src/examples/envvar.inline.envfile.js -E ./src/examples/.envfile`
4339
);
4440
expect(stdout).toContain('✅ main scenario completed');
45-
expect(stdout).toContain('The estimated footprint is');
46-
expect(error).toBeUndefined();
4741
});
48-
});
49-
describe('distant analysis', () => {
50-
it('should run an analysis command correctly', async () => {
51-
const { error, stdout } = await exec(
52-
`${BASE_COMMAND} ../../src/examples/greenframe.js https://greenframe.io -p GreenFrame -d -s 2`
53-
);
5442

43+
it('should work with env vars and config file', async () => {
44+
const { stdout } = await exec(
45+
`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`
46+
);
5547
expect(stdout).toContain('✅ main scenario completed');
56-
expect(stdout).toContain('The estimated footprint is');
57-
expect(stdout).toContain('Check the details of your analysis at');
58-
expect(error).toBeUndefined();
5948
});
6049

61-
it('should run an analysis command below a threshold', async () => {
62-
const { error, stdout } = await exec(
63-
`${BASE_COMMAND} ../../src/examples/greenframe.js https://greenframe.io -s 2 -p GreenFrame -d -t 0.1`
50+
it('should work with env file and config file', async () => {
51+
const { stdout } = await exec(
52+
`${BASE_COMMAND} https://www.google.fr -C ../../src/examples/envvar.config.envfile.yml`
6453
);
6554
expect(stdout).toContain('✅ main scenario completed');
66-
expect(stdout).toContain('The estimated footprint at');
67-
expect(stdout).toContain(
68-
'is under the limit configured at 0.1 g eq. co2.'
55+
});
56+
57+
it('should set greenframe browser locale right', async () => {
58+
const { stdout: enStdout } = await exec(
59+
`${BASE_COMMAND} -C ./e2e/.greenframe.single.en.yml`
6960
);
70-
expect(stdout).toContain('Check the details of your analysis at');
71-
expect(error).toBeUndefined();
61+
expect(enStdout).toContain('✅ main scenario completed');
62+
const { stdout: frStdout } = await exec(
63+
`${BASE_COMMAND} -C ./e2e/.greenframe.single.fr.yml`
64+
);
65+
expect(frStdout).toContain('✅ main scenario completed');
7266
});
7367

7468
it('should run an analysis command with adblocker', async () => {
7569
const { error, stdout } = await exec(
76-
`${BASE_COMMAND} ../../src/examples/greenframe.js https://greenframe.io -s 2 -p GreenFrame -d -a`
70+
`${BASE_COMMAND} -C ./e2e/.greenframe.adblock.yml`
7771
);
7872
expect(stdout).toContain('✅ main scenario completed');
7973
expect(stdout).toContain('The estimated footprint is');
80-
expect(stdout).toContain('Check the details of your analysis at');
81-
expect(error).toBeUndefined();
82-
});
83-
84-
it('should run an analysis and fail with higher measure than threshold', async () => {
85-
expect.assertions(3);
86-
try {
87-
await exec(
88-
`${BASE_COMMAND} ../../src/examples/greenframe.js https://greenframe.io -s 2 -p GreenFrame -d -t 0.001`
89-
);
90-
} catch (error) {
91-
expect(error.stderr).toContain('❌ main scenario failed');
92-
expect(error.stderr).toContain('The estimated footprint at');
93-
expect(error.stderr).toContain(
94-
'passes the limit configured at 0.001 g eq. co2.'
95-
);
96-
}
97-
});
98-
99-
it('should run an analysis with multiple scenario', async () => {
100-
const { error, stdout } = await exec(
101-
`${BASE_COMMAND} -C ./e2e/.greenframe.single.multiple.distant.yml`
102-
);
103-
expect(stdout).toContain('✅ Scenario 1 completed');
104-
expect(stdout).toContain(
105-
'is under the limit configured at 0.1 g eq. co2.'
106-
);
107-
expect(stdout).toContain('✅ Scenario 2 completed');
108-
expect(stdout).toContain(
109-
'is under the limit configured at 0.05 g eq. co2.'
110-
);
11174
expect(error).toBeUndefined();
11275
});
11376
});
@@ -223,20 +186,6 @@ describe.skip('[GREENFRAME.IO] greenframe analyze', () => {
223186
expect(error).toBeUndefined();
224187
});
225188

226-
it('should fail because distant mode is not compatible with multi containers', async () => {
227-
expect.assertions(2);
228-
try {
229-
await exec(
230-
`${BASE_COMMAND} -C ./e2e/.greenframe.fullstack.yml -d -s 2`
231-
);
232-
} catch (error) {
233-
expect(error.stderr).toContain('❌ Failed!');
234-
expect(error.stderr).toContain(
235-
'"distant" mode is incompatible with parameters "containers" or "databaseContainers"'
236-
);
237-
}
238-
});
239-
240189
it('should run a k8s analysis command correctly', async () => {
241190
const { error, stdout } = await exec(
242191
`${BASE_COMMAND} -C ./e2e/.greenframe.fullstack.k8s.yml`
@@ -248,19 +197,5 @@ describe.skip('[GREENFRAME.IO] greenframe analyze', () => {
248197
expect(error).toBeUndefined();
249198
});
250199
});
251-
252-
describe('distant analysis', () => {
253-
it('should fail because distant mode is not compatible with multi containers', async () => {
254-
expect.assertions(2);
255-
try {
256-
await exec(`${BASE_COMMAND} -C ./.greenframe.e2e.yml -d -s 2`);
257-
} catch (error) {
258-
expect(error.stderr).toContain('❌ Failed!');
259-
expect(error.stderr).toContain(
260-
'"distant" mode is incompatible with parameters "containers" or "databaseContainers"'
261-
);
262-
}
263-
});
264-
});
265200
});
266201
});

0 commit comments

Comments
 (0)