Skip to content

Commit

Permalink
Clean and document 1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienMattiussi committed Sep 25, 2023
1 parent 06dae39 commit 794280d
Show file tree
Hide file tree
Showing 19 changed files with 20 additions and 253 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ scenarios:
threshold: 0.1
projectName: YOUR_PROJECT_NAME
samples: 3
distant: false
//distant: "This option has been deprecated due to security issues"
useAdblock: true
ignoreHTTPSErrors: true
locale: 'fr-FR',
Expand All @@ -193,7 +193,11 @@ containers:
- 'CONTAINER_NAME'
- 'ANOTHER_CONTAINER_NAME'
databaseContainers:
- 'DATABASE_CONTAINER_NAME'
- 'DATABASE_CONTAINER_NAME',
envFile: PATH_TO_YOUR_ENVIRONNEMENT_VAR_FILE
envVar:
- envVarA: 'An environement variable needed for the scenario (ie : a secret-key)',
- envVarB: 'Another environement variable needed'
```
## More Information / Troubleshooting
Expand Down Expand Up @@ -233,10 +237,11 @@ This means that the lowest hanging fruit for optimizing the emissions of a web p
# Commands

<!-- commands -->
* [`greenframe analyze [BASEURL] [SCENARIO]`](#greenframe-analyze-baseurl-scenario)
* [`greenframe kube-config`](#greenframe-kube-config)
* [`greenframe open [BASEURL] [SCENARIO]`](#greenframe-open-baseurl-scenario)
* [`greenframe update [CHANNEL]`](#greenframe-update-channel)

- [`greenframe analyze [BASEURL] [SCENARIO]`](#greenframe-analyze-baseurl-scenario)
- [`greenframe kube-config`](#greenframe-kube-config)
- [`greenframe open [BASEURL] [SCENARIO]`](#greenframe-open-baseurl-scenario)
- [`greenframe update [CHANNEL]`](#greenframe-update-channel)

## `greenframe analyze [BASEURL] [SCENARIO]`

Expand Down Expand Up @@ -348,6 +353,7 @@ DESCRIPTION
```
_See code: [dist/commands/update.ts](https://github.com/marmelab/greenframe-cli/blob/v1.7.0/dist/commands/update.ts)_
<!-- commandsstop -->
## Development
Expand Down
1 change: 0 additions & 1 deletion e2e/.greenframe.fullstack.broken.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
scenario: '../../src/examples/greenframe.js'
baseURL: 'https://greenframe.io'
samples: 2
distant: false
projectName: 'GreenFrame'
containers:
- 'enterprise_api'
Expand Down
1 change: 0 additions & 1 deletion e2e/.greenframe.fullstack.emptyScenario.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
baseURL: 'https://greenframe.io'
samples: 2
distant: false
projectName: 'GreenFrame'
containers:
- 'enterprise_api'
Expand Down
1 change: 0 additions & 1 deletion e2e/.greenframe.fullstack.k8s.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
scenario: '../src/examples/greenframe.js'
baseURL: 'https://greenframe.io'
samples: 2
distant: false
projectName: 'GreenFrame'
kubeContainers:
- 'default:app=api'
Expand Down
1 change: 0 additions & 1 deletion e2e/.greenframe.fullstack.multiple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ scenarios:
threshold: 0.05
baseURL: 'https://greenframe.io'
samples: 2
distant: false
projectName: 'GreenFrame'
containers:
- 'enterprise_api'
Expand Down
1 change: 0 additions & 1 deletion e2e/.greenframe.fullstack.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
scenario: '../src/examples/greenframe.js'
baseURL: 'https://greenframe.io'
samples: 2
distant: false
projectName: 'GreenFrame'
containers:
- 'enterprise_api'
Expand Down
1 change: 0 additions & 1 deletion e2e/.greenframe.single.adblock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ scenario: '../../src/examples/greenframe.js'
baseURL: 'https://greenframe.io'
samples: 2
projectName: 'GreenFrame'
distant: false
useAdblock: true
1 change: 0 additions & 1 deletion e2e/.greenframe.single.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ scenario: '../../src/examples/marmelab.en.js'
baseURL: 'https://marmelab.com'
samples: 2
projectName: 'Marmelab'
distant: false
useAdblock: true
locale: en-US
1 change: 0 additions & 1 deletion e2e/.greenframe.single.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ scenario: '../../src/examples/marmelab.fr.js'
baseURL: 'https://marmelab.com'
samples: 2
projectName: 'Marmelab'
distant: false
useAdblock: true
locale: fr-FR
1 change: 0 additions & 1 deletion e2e/.greenframe.single.multiple.distant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ scenarios:
threshold: 0.05
baseURL: 'https://greenframe.io'
samples: 2
distant: true
projectName: 'GreenFrame'
93 changes: 0 additions & 93 deletions e2e/greenframe.io/analyze.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,71 +74,6 @@ describe.skip('[GREENFRAME.IO] greenframe analyze', () => {
expect(error).toBeUndefined();
});
});
describe('distant analysis', () => {
it('should run an analysis command correctly', async () => {
const { error, stdout } = await exec(
`${BASE_COMMAND} ../../src/examples/greenframe.js https://greenframe.io -p GreenFrame -d -s 2`
);

expect(stdout).toContain('✅ main scenario completed');
expect(stdout).toContain('The estimated footprint is');
expect(stdout).toContain('Check the details of your analysis at');
expect(error).toBeUndefined();
});

it('should run an analysis command below a threshold', async () => {
const { error, stdout } = await exec(
`${BASE_COMMAND} ../../src/examples/greenframe.js https://greenframe.io -s 2 -p GreenFrame -d -t 0.1`
);
expect(stdout).toContain('✅ main scenario completed');
expect(stdout).toContain('The estimated footprint at');
expect(stdout).toContain(
'is under the limit configured at 0.1 g eq. co2.'
);
expect(stdout).toContain('Check the details of your analysis at');
expect(error).toBeUndefined();
});

it('should run an analysis command with adblocker', async () => {
const { error, stdout } = await exec(
`${BASE_COMMAND} ../../src/examples/greenframe.js https://greenframe.io -s 2 -p GreenFrame -d -a`
);
expect(stdout).toContain('✅ main scenario completed');
expect(stdout).toContain('The estimated footprint is');
expect(stdout).toContain('Check the details of your analysis at');
expect(error).toBeUndefined();
});

it('should run an analysis and fail with higher measure than threshold', async () => {
expect.assertions(3);
try {
await exec(
`${BASE_COMMAND} ../../src/examples/greenframe.js https://greenframe.io -s 2 -p GreenFrame -d -t 0.001`
);
} catch (error) {
expect(error.stderr).toContain('❌ main scenario failed');
expect(error.stderr).toContain('The estimated footprint at');
expect(error.stderr).toContain(
'passes the limit configured at 0.001 g eq. co2.'
);
}
});

it('should run an analysis with multiple scenario', async () => {
const { error, stdout } = await exec(
`${BASE_COMMAND} -C ./e2e/.greenframe.single.multiple.distant.yml`
);
expect(stdout).toContain('✅ Scenario 1 completed');
expect(stdout).toContain(
'is under the limit configured at 0.1 g eq. co2.'
);
expect(stdout).toContain('✅ Scenario 2 completed');
expect(stdout).toContain(
'is under the limit configured at 0.05 g eq. co2.'
);
expect(error).toBeUndefined();
});
});
});

describe('full stack', () => {
Expand Down Expand Up @@ -251,20 +186,6 @@ describe.skip('[GREENFRAME.IO] greenframe analyze', () => {
expect(error).toBeUndefined();
});

it('should fail because distant mode is not compatible with multi containers', async () => {
expect.assertions(2);
try {
await exec(
`${BASE_COMMAND} -C ./e2e/.greenframe.fullstack.yml -d -s 2`
);
} catch (error) {
expect(error.stderr).toContain('❌ Failed!');
expect(error.stderr).toContain(
'"distant" mode is incompatible with parameters "containers" or "databaseContainers"'
);
}
});

it('should run a k8s analysis command correctly', async () => {
const { error, stdout } = await exec(
`${BASE_COMMAND} -C ./e2e/.greenframe.fullstack.k8s.yml`
Expand All @@ -276,19 +197,5 @@ describe.skip('[GREENFRAME.IO] greenframe analyze', () => {
expect(error).toBeUndefined();
});
});

describe('distant analysis', () => {
it('should fail because distant mode is not compatible with multi containers', async () => {
expect.assertions(2);
try {
await exec(`${BASE_COMMAND} -C ./.greenframe.e2e.yml -d -s 2`);
} catch (error) {
expect(error.stderr).toContain('❌ Failed!');
expect(error.stderr).toContain(
'"distant" mode is incompatible with parameters "containers" or "databaseContainers"'
);
}
});
});
});
});
93 changes: 0 additions & 93 deletions e2e/local/analyze.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,71 +44,6 @@ describe('[LOCAL] greenframe analyze', () => {
expect(error).toBeUndefined();
});
});

// we need to setup a mock greenframe.io environment to enable this test
// eslint-disable-next-line jest/no-disabled-tests
describe.skip('distant analysis', () => {
it('should run an analysis command correctly', async () => {
const { error, stdout } = await exec(
`${BASE_COMMAND} ../../src/examples/greenframe.js https://greenframe.io -p GreenFrame -d -s 2`
);

expect(stdout).toContain('✅ main scenario completed');
expect(stdout).toContain('The estimated footprint is');
expect(error).toBeUndefined();
});

it('should run an analysis command below a threshold', async () => {
const { error, stdout } = await exec(
`${BASE_COMMAND} ../../src/examples/greenframe.js https://greenframe.io -s 2 -p GreenFrame -d -t 0.1`
);
expect(stdout).toContain('✅ main scenario completed');
expect(stdout).toContain('The estimated footprint at');
expect(stdout).toContain(
'is under the limit configured at 0.1 g eq. co2.'
);
expect(error).toBeUndefined();
});

it('should run an analysis command with adblocker', async () => {
const { error, stdout } = await exec(
`${BASE_COMMAND} ../../src/examples/greenframe.js https://greenframe.io -s 2 -p GreenFrame -d -a`
);
expect(stdout).toContain('✅ main scenario completed');
expect(stdout).toContain('The estimated footprint is');
expect(error).toBeUndefined();
});

it('should run an analysis and fail with higher measure than threshold', async () => {
expect.assertions(3);
try {
await exec(
`${BASE_COMMAND} ../../src/examples/greenframe.js https://greenframe.io -s 2 -p GreenFrame -d -t 0.001`
);
} catch (error) {
expect(error.stderr).toContain('❌ main scenario failed');
expect(error.stderr).toContain('The estimated footprint at');
expect(error.stderr).toContain(
'passes the limit configured at 0.001 g eq. co2.'
);
}
});

it('should run an analysis with multiple scenario', async () => {
const { error, stdout } = await exec(
`${BASE_COMMAND} -C ./e2e/.greenframe.single.multiple.distant.yml`
);
expect(stdout).toContain('✅ Scenario 1 completed');
expect(stdout).toContain(
'is under the limit configured at 0.1 g eq. co2.'
);
expect(stdout).toContain('✅ Scenario 2 completed');
expect(stdout).toContain(
'is under the limit configured at 0.05 g eq. co2.'
);
expect(error).toBeUndefined();
});
});
});

// we need to setup a mock dev environment to enable this test
Expand Down Expand Up @@ -205,20 +140,6 @@ describe('[LOCAL] greenframe analyze', () => {
expect(error).toBeUndefined();
});

it('should fail because distant mode is not compatible with multi containers', async () => {
expect.assertions(2);
try {
await exec(
`${BASE_COMMAND} -C ./e2e/.greenframe.fullstack.yml -d -s 2`
);
} catch (error) {
expect(error.stderr).toContain('❌ Failed!');
expect(error.stderr).toContain(
'"distant" mode is incompatible with parameters "containers" or "databaseContainers"'
);
}
});

// This is disabled because it requires a kubernetes cluster to be running while testing
// eslint-disable-next-line jest/no-disabled-tests
it.skip('should run a k8s analysis command correctly', async () => {
Expand All @@ -231,19 +152,5 @@ describe('[LOCAL] greenframe analyze', () => {
expect(error).toBeUndefined();
});
});

describe('distant analysis', () => {
it('should fail because distant mode is not compatible with multi containers', async () => {
expect.assertions(2);
try {
await exec(`${BASE_COMMAND} -C ./.greenframe.e2e.yml -d -s 2`);
} catch (error) {
expect(error.stderr).toContain('❌ Failed!');
expect(error.stderr).toContain(
'"distant" mode is incompatible with parameters "containers" or "databaseContainers"'
);
}
});
});
});
});
9 changes: 2 additions & 7 deletions src/commands/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class AnalyzeCommand extends Command {
static defaultFlags = {
configFile: DEFAULT_CONFIG_FILE,
samples: DEFAULT_SAMPLES,
distant: false,
useAdblock: false,
ignoreHTTPSErrors: false,
};
Expand Down Expand Up @@ -76,10 +75,6 @@ class AnalyzeCommand extends Command {
char: 's',
description: 'Number of runs done for the score computation',
}),
distant: Flags.boolean({
char: 'd',
description: 'Run a distant analysis on GreenFrame Server instead of locally',
}),
useAdblock: Flags.boolean({
char: 'a',
description: 'Use an adblocker during analysis',
Expand Down Expand Up @@ -140,7 +135,7 @@ class AnalyzeCommand extends Command {
commandParams
);

const isDistant = flags.distant;
const isDistant = false;
const isFree = process.env.GREENFRAME_SECRET_TOKEN == null;
const tasks = new Listr(
[
Expand Down Expand Up @@ -219,7 +214,7 @@ class AnalyzeCommand extends Command {
}
);
const { result } = await tasks.run();
displayAnalysisResults(result, isFree, isDistant);
displayAnalysisResults(result, isFree);
} catch (error: any) {
console.error('\n❌ Failed!');
console.error(error.name);
Expand Down
5 changes: 2 additions & 3 deletions src/services/__tests__/parseConfigFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ describe('#resolveParams', () => {
scenarios: [{ path: 'PATH_TO_SCENARIO' }],
baseURL: 'YOUR_BASE_URL',
},
flags: { samples: 4, distant: true },
flags: { samples: 4 },
},
{
flags: { distant: false },
flags: {},
args: {
baseURL: 'ANOTHER_BASE_URL',
},
Expand All @@ -120,7 +120,6 @@ describe('#resolveParams', () => {
expect(flags).toEqual({
default: 'DEFAULT',
samples: 4,
distant: false,
});

expect(args).toEqual({
Expand Down
Loading

0 comments on commit 794280d

Please sign in to comment.