Skip to content

Commit 3eb3839

Browse files
committed
[#104] Add test documentation and simplify testData usage
1 parent 7b56e1c commit 3eb3839

File tree

9 files changed

+116
-102
lines changed

9 files changed

+116
-102
lines changed

packages/cli-tool/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ DESCRIPTION
7979

8080
## How to contribute
8181

82+
### Run
83+
8284
To run the CLI on your local machine:
8385

8486
```bash
@@ -97,6 +99,17 @@ If your changes also impacted the `cra-template` package, you can still test the
9799

98100
Find more the [OCLIF Documentation](https://oclif.io/docs/introduction.html)!
99101

102+
### Test
103+
104+
The tests generated from the combinaison of:
105+
- `TestData` objects
106+
- `Scenario` objects
107+
108+
`TestData` objects gather all the rules that should be tested for a given add-on.
109+
When creating a new add-on, you need to create a new associated TestData object in the `./test/add-ons/**` folder.
110+
111+
`Scenario` objects enable to run the tests of multiple add-ons in a single `generate` command execution. As running the `generate` command is time-consuming, grouping several add-ons tests into a single scenario is a way to get tests results earlier.
112+
100113
## License
101114

102115
This project is Copyright (c) 2014 and onwards.
Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import { TestData } from '../../helpers/test-data';
22

3-
export const bootstrapTestData = (projectName: string): TestData => {
4-
return {
5-
filesShouldContain: [
6-
{
7-
path: `${projectName}/package.json`,
8-
shouldContainString: 'bootstrap',
9-
},
10-
{
11-
path: `${projectName}/src/assets/stylesheets/application.scss`,
12-
shouldContainString: 'vendor/bootstrap',
13-
},
14-
],
15-
filesShouldExist: [
16-
`${projectName}/src/assets/stylesheets/vendor/bootstrap/index.scss`,
17-
],
18-
filesShouldNotExist: [
19-
`${projectName}/tailwind.config.js`,
20-
`${projectName}/src/assets/stylesheets/application.css`,
21-
],
22-
};
3+
export const bootstrapTestData: TestData = {
4+
filesShouldExist: [
5+
'/src/assets/stylesheets/vendor/bootstrap/index.scss',
6+
],
7+
filesShouldNotExist: [
8+
'/tailwind.config.js',
9+
'/src/assets/stylesheets/application.css',
10+
],
11+
filesShouldContain: [
12+
{
13+
path: '/package.json',
14+
shouldContainString: 'bootstrap',
15+
},
16+
{
17+
path: '/src/assets/stylesheets/application.scss',
18+
shouldContainString: 'vendor/bootstrap',
19+
},
20+
],
2321
};
Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
import { TestData } from '../../helpers/test-data';
22

3-
export const tailwindCssTestData = (projectName: string): TestData => {
4-
return {
5-
filesShouldExist: [
6-
`${projectName}/tailwind.config.js`,
7-
`${projectName}/postcss.config.js`,
8-
`${projectName}/src/assets/stylesheets/application.css`,
9-
],
10-
filesShouldNotExist: [
11-
`${projectName}/src/assets/stylesheets/vendor/bootstrap`,
12-
`${projectName}/src/assets/stylesheets/application.scss`,
13-
],
14-
filesShouldContain: [
15-
{
16-
path: `${projectName}/package.json`,
17-
shouldContainString: 'tailwindcss',
18-
},
19-
{
20-
path: `${projectName}/package.json`,
21-
shouldContainString: 'postcss-import',
22-
},
23-
{
24-
path: `${projectName}/src/assets/stylesheets/application.css`,
25-
shouldContainString: '@tailwind base;',
26-
},
27-
{
28-
path: `${projectName}/src/assets/stylesheets/application.css`,
29-
shouldContainString: '@tailwind components;',
30-
},
31-
{
32-
path: `${projectName}/src/assets/stylesheets/application.css`,
33-
shouldContainString: '@tailwind utilities;',
34-
},
35-
],
36-
};
3+
export const tailwindCssTestData: TestData = {
4+
filesShouldExist: [
5+
'/tailwind.config.js',
6+
'/postcss.config.js',
7+
'/src/assets/stylesheets/application.css',
8+
],
9+
filesShouldNotExist: [
10+
'/src/assets/stylesheets/vendor/bootstrap',
11+
'/src/assets/stylesheets/application.scss',
12+
],
13+
filesShouldContain: [
14+
{
15+
path: '/package.json',
16+
shouldContainString: 'tailwindcss',
17+
},
18+
{
19+
path: '/package.json',
20+
shouldContainString: 'postcss-import',
21+
},
22+
{
23+
path: '/src/assets/stylesheets/application.css',
24+
shouldContainString: '@tailwind base;',
25+
},
26+
{
27+
path: '/src/assets/stylesheets/application.css',
28+
shouldContainString: '@tailwind components;',
29+
},
30+
{
31+
path: '/src/assets/stylesheets/application.css',
32+
shouldContainString: '@tailwind utilities;',
33+
},
34+
],
3735
};

packages/cli-tool/test/add-ons/version-control/github.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/cli-tool/test/add-ons/version-control/gitlab.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { TestData } from '../../helpers/test-data';
2+
3+
export const gitHubTestData: TestData = {
4+
filesShouldExist: ['/.github'],
5+
filesShouldNotExist: ['/.gitlab'],
6+
filesShouldContain: [],
7+
};
8+
9+
export const gitLabTestData: TestData = {
10+
filesShouldExist: ['/.gitlab'],
11+
filesShouldNotExist: ['/.github'],
12+
filesShouldContain: [],
13+
};

packages/cli-tool/test/commands/generate/index.test.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@ import Inquirer from 'inquirer';
55

66
import { bootstrapTestData } from '../../add-ons/ui-framework/bootstrap';
77
import { tailwindCssTestData } from '../../add-ons/ui-framework/tailwind-css';
8-
import { gitHubTestData } from '../../add-ons/version-control/github';
9-
import { gitLabTestData } from '../../add-ons/version-control/gitlab';
8+
import { gitHubTestData, gitLabTestData } from '../../add-ons/version-control';
109
import { TestScenario } from '../../helpers/test-scenario';
1110

1211
const templateRepoPath = 'file:./packages/cra-template';
1312
const projectName = 'test-app';
1413
const testFolderPath = '../../';
1514

16-
const gitHubData = gitHubTestData(projectName);
17-
const gitLabData = gitLabTestData(projectName);
18-
19-
const bootstrapData = bootstrapTestData(projectName);
20-
const tailwindCssData = tailwindCssTestData(projectName);
15+
const projectPath = `${testFolderPath}${projectName}`;
2116

2217
const testScenarios: TestScenario[] = [
2318
{
@@ -27,16 +22,16 @@ const testScenarios: TestScenario[] = [
2722
},
2823
testData: {
2924
filesShouldExist: [
30-
...gitHubData.filesShouldExist,
31-
...bootstrapData.filesShouldExist,
25+
...gitHubTestData.filesShouldExist,
26+
...bootstrapTestData.filesShouldExist,
3227
],
3328
filesShouldNotExist: [
34-
...gitHubData.filesShouldNotExist,
35-
...bootstrapData.filesShouldNotExist,
29+
...gitHubTestData.filesShouldNotExist,
30+
...bootstrapTestData.filesShouldNotExist,
3631
],
3732
filesShouldContain: [
38-
...gitHubData.filesShouldContain,
39-
...bootstrapData.filesShouldContain,
33+
...gitHubTestData.filesShouldContain,
34+
...bootstrapTestData.filesShouldContain,
4035
],
4136
},
4237
},
@@ -47,16 +42,16 @@ const testScenarios: TestScenario[] = [
4742
},
4843
testData: {
4944
filesShouldExist: [
50-
...gitLabData.filesShouldExist,
51-
...tailwindCssData.filesShouldExist,
45+
...gitLabTestData.filesShouldExist,
46+
...tailwindCssTestData.filesShouldExist,
5247
],
5348
filesShouldNotExist: [
54-
...gitLabData.filesShouldNotExist,
55-
...tailwindCssData.filesShouldNotExist,
49+
...gitLabTestData.filesShouldNotExist,
50+
...tailwindCssTestData.filesShouldNotExist,
5651
],
5752
filesShouldContain: [
58-
...gitLabData.filesShouldContain,
59-
...tailwindCssData.filesShouldContain,
53+
...gitLabTestData.filesShouldContain,
54+
...tailwindCssTestData.filesShouldContain,
6055
],
6156
},
6257
},
@@ -93,16 +88,16 @@ describe('generate', () => {
9388
);
9489

9590
scenario.testData.filesShouldExist.forEach((file) => {
96-
expect(fs.existsSync(`${testFolderPath}${file}`)).to.equal(true);
91+
expect(fs.existsSync(`${projectPath}${file}`)).to.equal(true);
9792
});
9893

9994
scenario.testData.filesShouldNotExist.forEach((file) => {
100-
expect(fs.existsSync(`${testFolderPath}${file}`)).to.equal(false);
95+
expect(fs.existsSync(`${projectPath}${file}`)).to.equal(false);
10196
});
10297

10398
scenario.testData.filesShouldContain.forEach((file) => {
10499
const contents = fs.readFileSync(
105-
`${testFolderPath}${file.path}`,
100+
`${projectPath}${file.path}`,
106101
'utf-8',
107102
);
108103

packages/cli-tool/test/helpers/test-data.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
1+
/** Describe all tests to be run for a given add-on */
12
export type TestData = {
3+
/** Path relative to the generated project root folder.
4+
* List files or folders that are expected to be included within
5+
* the generated project.
6+
* E.g. '/src/assets/stylesheets/application.scss`
7+
*/
28
filesShouldExist: string[];
9+
/** Path relative to the generated project root folder.
10+
* List files or folders that are expected to NOT be included within
11+
* the generated project.
12+
* E.g. '/src/assets/stylesheets/vendor/bootstrap`
13+
*/
314
filesShouldNotExist: string[];
15+
/** Path relative to the generated project root folder.
16+
* List what file is expected to contain what string.
17+
* E.g.
18+
* ```
19+
* {
20+
* path: '/src/assets/stylesheets/application.scss`,
21+
* shouldContainString: 'vendor/bootstrap`,
22+
* }
23+
* ```
24+
*/
425
filesShouldContain: {
526
path: string;
627
shouldContainString: string;

packages/cli-tool/test/helpers/test-scenario.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { TestData } from './test-data';
22

3+
/** TestScenario group several add-ons tests
4+
* into a single generate command execution */
35
export type TestScenario = {
46
options: any; // eslint-disable-line @typescript-eslint/no-explicit-any
57
testData: TestData;

0 commit comments

Comments
 (0)