Skip to content

Commit d2e6c4e

Browse files
committed
[#121] Add additonal test scenario
1 parent 3568cda commit d2e6c4e

File tree

11 files changed

+81
-73
lines changed

11 files changed

+81
-73
lines changed

packages/cli-tool/src/template/fetchingStrategy/copyStrategy.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { CliUx } from '@oclif/core';
22

3+
import { FetchStrategy } from '.';
34
import { InitTemplateOptions } from '../.';
45
import runCommand from '../../helpers/child-process';
5-
import { FetchStrategy } from './';
6-
7-
const TEMPLATE_SOURCE_FILES = '../vite-template';
86

97
class CopyStrategy implements FetchStrategy {
8+
constructor(public selectedTemplate: string) {
9+
this.selectedTemplate = selectedTemplate;
10+
}
11+
1012
async fetchTemplateFiles(options: InitTemplateOptions): Promise<void> {
1113
return this.copyTemplateFiles(options)
1214
.then(() => this.renameFolder(options));
@@ -17,7 +19,7 @@ class CopyStrategy implements FetchStrategy {
1719

1820
return runCommand(
1921
'cp',
20-
['-r', TEMPLATE_SOURCE_FILES, options.dest],
22+
['-r', `../${this.selectedTemplate}`, options.dest],
2123
);
2224
}
2325

@@ -26,7 +28,7 @@ class CopyStrategy implements FetchStrategy {
2628

2729
return runCommand(
2830
'mv',
29-
[`${options.dest}/vite-template`, `${options.dest}/${options.appName}`],
31+
[`${options.dest}/${this.selectedTemplate}/`, `${options.dest}/${options.appName}/`],
3032
);
3133
}
3234
}

packages/cli-tool/src/template/fetchingStrategy/downloadStrategy.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import { CliUx } from '@oclif/core';
22

3+
import { FetchStrategy } from '.';
34
import { InitTemplateOptions } from '../.';
45
import runCommand from '../../helpers/child-process';
56
import { downloadRepository } from '../../helpers/github';
6-
import { FetchStrategy } from './';
77

88
const TEMPLATE_OWNER = 'nimblehq';
99
const TEMPLATE_REPO = 'react-templates';
1010

1111
class DownloadStrategy implements FetchStrategy {
12+
constructor(public selectedTemplate: string) {
13+
this.selectedTemplate = selectedTemplate;
14+
}
15+
1216
async fetchTemplateFiles(options: InitTemplateOptions): Promise<void> {
1317
return this.downloadTemplateRepository(options)
14-
.then(() => this.extractViteTemplateFolder(options))
18+
.then(() => this.extractDownloadedTemplateFolder(options))
1519
.then(() => this.renameFolder(options))
1620
.then(() => this.cleanTemporaryFiles(options));
1721
}
@@ -32,7 +36,7 @@ class DownloadStrategy implements FetchStrategy {
3236
);
3337
}
3438

35-
private extractViteTemplateFolder(options: InitTemplateOptions): Promise<void> {
39+
private extractDownloadedTemplateFolder(options: InitTemplateOptions): Promise<void> {
3640
CliUx.ux.info('Extracting template source files...');
3741

3842
return runCommand(
@@ -48,7 +52,7 @@ class DownloadStrategy implements FetchStrategy {
4852

4953
return runCommand(
5054
'mv',
51-
[`${TEMPLATE_REPO}-${path}`, options.appName],
55+
[`${TEMPLATE_REPO}-${path}/${this.selectedTemplate}/`, options.appName],
5256
options.dest,
5357
);
5458
}

packages/cli-tool/src/template/fetchingStrategy/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { InitTemplateOptions } from '../.';
22
import CopyStrategy from './copyStrategy';
33
import DownloadStrategy from './downloadStrategy';
44

5-
export type FetchStrategy = {
6-
fetchTemplateFiles: (options: InitTemplateOptions) => Promise<void>;
7-
};
5+
export interface FetchStrategy {
6+
selectedTemplate: string;
7+
8+
fetchTemplateFiles(options: InitTemplateOptions): Promise<void>;
9+
}
810

911
export { CopyStrategy, DownloadStrategy };

packages/cli-tool/src/template/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export const TEMPLATE_OPTIONS = new Map<templateOptions, string>([
1616

1717
export const initializeTemplate = async({
1818
appName,
19+
dest,
1920
templateOption,
2021
templateReference,
21-
dest,
2222
}: {
2323
templateOption: templateOptions;
2424
} & InitTemplateOptions): Promise<void> => {

packages/cli-tool/src/template/initialize-vite-app.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ const replcaeNimbleNameInFiles = ['package.json'];
1111
const fetchTemplateFiles = (options: InitTemplateOptions): Promise<void> => {
1212
let fetchStrategy: CopyStrategy | DownloadStrategy;
1313

14-
// If passed templateReference in CLI, use the DownloadStrategy
15-
// TODO: Decide if we want to keep DownloadStrategy long-term
16-
if (options.templateReference && options.templateReference.trim() === '') {
17-
fetchStrategy = new DownloadStrategy();
14+
// TODO: Decide if we want to use DownloadStrategy long-term
15+
if (!options.templateReference || options.templateReference.trim() === '') {
16+
fetchStrategy = new CopyStrategy('vite-template');
1817
} else {
19-
fetchStrategy = new CopyStrategy();
18+
fetchStrategy = new DownloadStrategy('vite-template');
2019
}
2120

2221
return fetchStrategy.fetchTemplateFiles(options);

packages/cli-tool/test/add-ons/ui-framework/bootstrap.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { TestData } from '../../helpers/test-data';
22

33
export const bootstrapTestData: TestData = {
4-
filesShouldExist: [
4+
filePaths: [
55
'/src/assets/stylesheets/vendor/bootstrap/index.scss',
66
],
7-
filesShouldNotExist: [
8-
'/tailwind.config.js',
9-
'/src/assets/stylesheets/application.css',
10-
],
117
filesShouldContain: [
128
{
139
path: '/package.json',

packages/cli-tool/test/add-ons/ui-framework/tailwind-css.ts

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

33
export const tailwindCssTestData: TestData = {
4-
filesShouldExist: [
4+
filePaths: [
55
'/tailwind.config.js',
66
'/postcss.config.js',
77
'/src/assets/stylesheets/application.css',
88
],
9-
filesShouldNotExist: [
10-
'/src/assets/stylesheets/vendor/bootstrap',
11-
'/src/assets/stylesheets/application.scss',
12-
],
139
filesShouldContain: [
1410
{
1511
path: '/package.json',
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import { TestData } from '../../helpers/test-data';
22

33
export const gitHubTestData: TestData = {
4-
filesShouldExist: ['/.github'],
5-
filesShouldNotExist: ['/.gitlab'],
4+
filePaths: ['/.github'],
65
filesShouldContain: [],
76
};
87

98
export const gitLabTestData: TestData = {
10-
filesShouldExist: ['/.gitlab'],
11-
filesShouldNotExist: ['/.github'],
9+
filePaths: ['/.gitlab'],
1210
filesShouldContain: [],
1311
};
1412

1513
export const noVersionControlTestData: TestData = {
16-
filesShouldExist: [],
17-
filesShouldNotExist: ['/.github', '/.gitlab'],
14+
filePaths: ['/.github', '/.gitlab'],
1815
filesShouldContain: [],
1916
};

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

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ const viteTestScenarios: TestScenario[] = [
2626
templateReference: viteTemplateReference,
2727
testData: {
2828
filesShouldExist: [
29-
...gitHubTestData.filesShouldExist,
30-
...bootstrapTestData.filesShouldExist,
29+
...gitHubTestData.filePaths,
30+
...bootstrapTestData.filePaths,
3131
],
3232
filesShouldNotExist: [
33-
...gitHubTestData.filesShouldNotExist,
34-
...bootstrapTestData.filesShouldNotExist,
33+
...gitLabTestData.filePaths,
34+
...tailwindCssTestData.filePaths,
3535
],
3636
filesShouldContain: [
3737
...gitHubTestData.filesShouldContain,
@@ -48,12 +48,12 @@ const viteTestScenarios: TestScenario[] = [
4848
templateReference: viteTemplateReference,
4949
testData: {
5050
filesShouldExist: [
51-
...gitLabTestData.filesShouldExist,
52-
...tailwindCssTestData.filesShouldExist,
51+
...gitLabTestData.filePaths,
52+
...tailwindCssTestData.filePaths,
5353
],
5454
filesShouldNotExist: [
55-
...gitLabTestData.filesShouldNotExist,
56-
...tailwindCssTestData.filesShouldNotExist,
55+
...gitHubTestData.filePaths,
56+
...bootstrapTestData.filePaths,
5757
],
5858
filesShouldContain: [
5959
...gitLabTestData.filesShouldContain,
@@ -64,23 +64,18 @@ const viteTestScenarios: TestScenario[] = [
6464
{
6565
options: {
6666
template: 'vite',
67-
versionControl: 'github',
68-
uiFramework: 'bootstrap',
67+
versionControl: 'none',
68+
uiFramework: 'none',
6969
},
7070
templateReference: '',
7171
testData: {
72-
filesShouldExist: [
73-
...gitHubTestData.filesShouldExist,
74-
...bootstrapTestData.filesShouldExist,
75-
],
72+
filesShouldExist: [],
7673
filesShouldNotExist: [
77-
...gitHubTestData.filesShouldNotExist,
78-
...bootstrapTestData.filesShouldNotExist,
79-
],
80-
filesShouldContain: [
81-
...gitHubTestData.filesShouldContain,
82-
...bootstrapTestData.filesShouldContain,
74+
...noVersionControlTestData.filePaths,
75+
...bootstrapTestData.filePaths,
76+
...tailwindCssTestData.filePaths,
8377
],
78+
filesShouldContain: [],
8479
},
8580
},
8681
];
@@ -94,12 +89,12 @@ const craTestScenarios: TestScenario[] = [
9489
templateReference: craTemplateReference,
9590
testData: {
9691
filesShouldExist: [
97-
...gitHubTestData.filesShouldExist,
98-
...bootstrapTestData.filesShouldExist,
92+
...gitHubTestData.filePaths,
93+
...bootstrapTestData.filePaths,
9994
],
10095
filesShouldNotExist: [
101-
...gitHubTestData.filesShouldNotExist,
102-
...bootstrapTestData.filesShouldNotExist,
96+
...gitLabTestData.filePaths,
97+
...tailwindCssTestData.filePaths,
10398
],
10499
filesShouldContain: [
105100
...gitHubTestData.filesShouldContain,
@@ -116,15 +111,13 @@ const craTestScenarios: TestScenario[] = [
116111
templateReference: craTemplateReference,
117112
testData: {
118113
filesShouldExist: [
119-
...noVersionControlTestData.filesShouldExist,
120-
...tailwindCssTestData.filesShouldExist,
114+
...tailwindCssTestData.filePaths,
121115
],
122116
filesShouldNotExist: [
123-
...noVersionControlTestData.filesShouldNotExist,
124-
...tailwindCssTestData.filesShouldNotExist,
117+
...noVersionControlTestData.filePaths,
118+
...bootstrapTestData.filePaths,
125119
],
126120
filesShouldContain: [
127-
...noVersionControlTestData.filesShouldContain,
128121
...tailwindCssTestData.filesShouldContain,
129122
],
130123
},

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ export type TestData = {
55
* the generated project.
66
* E.g. '/src/assets/stylesheets/application.scss`
77
*/
8-
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-
*/
14-
filesShouldNotExist: string[];
8+
filePaths: string[];
159
/** Path relative to the generated project root folder.
1610
* List what file is expected to contain what string.
1711
* E.g.
Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
1-
import { TestData } from './test-data';
2-
31
/** TestScenario group several add-ons tests
42
* into a single generate command execution */
53
export type TestScenario = {
64
options: any; // eslint-disable-line @typescript-eslint/no-explicit-any
75
templateReference: string;
8-
testData: TestData;
6+
testData: {
7+
/** Path relative to the generated project root folder.
8+
* List files or folders that are expected to be included within
9+
* the generated project.
10+
* E.g. '/src/assets/stylesheets/application.scss`
11+
*/
12+
filesShouldExist: string[];
13+
/** Path relative to the generated project root folder.
14+
* List files or folders that are expected to NOT be included within
15+
* the generated project.
16+
* E.g. '/src/assets/stylesheets/vendor/bootstrap`
17+
*/
18+
filesShouldNotExist: string[];
19+
/** Path relative to the generated project root folder.
20+
* List what file is expected to contain what string.
21+
* E.g.
22+
* ```
23+
* {
24+
* path: '/src/assets/stylesheets/application.scss`,
25+
* shouldContainString: 'vendor/bootstrap`,
26+
* }
27+
* ```
28+
*/
29+
filesShouldContain: {
30+
path: string;
31+
shouldContainString: string;
32+
}[];
33+
};
934
};

0 commit comments

Comments
 (0)