Skip to content

Commit

Permalink
[#121] Add additonal test scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
bterone committed Sep 29, 2023
1 parent 3568cda commit fa93b0b
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 59 deletions.
2 changes: 1 addition & 1 deletion packages/cli-tool/src/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export const TEMPLATE_OPTIONS = new Map<templateOptions, string>([

export const initializeTemplate = async({
appName,
dest,
templateOption,
templateReference,
dest,
}: {
templateOption: templateOptions;
} & InitTemplateOptions): Promise<void> => {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli-tool/src/template/initialize-vite-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const fetchTemplateFiles = (options: InitTemplateOptions): Promise<void> => {

// If passed templateReference in CLI, use the DownloadStrategy
// TODO: Decide if we want to keep DownloadStrategy long-term
if (options.templateReference && options.templateReference.trim() === '') {
fetchStrategy = new DownloadStrategy();
} else {
if (!options.templateReference || options.templateReference.trim() === '') {
fetchStrategy = new CopyStrategy();
} else {
fetchStrategy = new DownloadStrategy();
}

return fetchStrategy.fetchTemplateFiles(options);
Expand Down
6 changes: 1 addition & 5 deletions packages/cli-tool/test/add-ons/ui-framework/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { TestData } from '../../helpers/test-data';

export const bootstrapTestData: TestData = {
filesShouldExist: [
filePaths: [
'/src/assets/stylesheets/vendor/bootstrap/index.scss',
],
filesShouldNotExist: [
'/tailwind.config.js',
'/src/assets/stylesheets/application.css',
],
filesShouldContain: [
{
path: '/package.json',
Expand Down
6 changes: 1 addition & 5 deletions packages/cli-tool/test/add-ons/ui-framework/tailwind-css.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { TestData } from '../../helpers/test-data';

export const tailwindCssTestData: TestData = {
filesShouldExist: [
filePaths: [
'/tailwind.config.js',
'/postcss.config.js',
'/src/assets/stylesheets/application.css',
],
filesShouldNotExist: [
'/src/assets/stylesheets/vendor/bootstrap',
'/src/assets/stylesheets/application.scss',
],
filesShouldContain: [
{
path: '/package.json',
Expand Down
9 changes: 3 additions & 6 deletions packages/cli-tool/test/add-ons/version-control/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { TestData } from '../../helpers/test-data';

export const gitHubTestData: TestData = {
filesShouldExist: ['/.github'],
filesShouldNotExist: ['/.gitlab'],
filePaths: ['/.github'],
filesShouldContain: [],
};

export const gitLabTestData: TestData = {
filesShouldExist: ['/.gitlab'],
filesShouldNotExist: ['/.github'],
filePaths: ['/.gitlab'],
filesShouldContain: [],
};

export const noVersionControlTestData: TestData = {
filesShouldExist: [],
filesShouldNotExist: ['/.github', '/.gitlab'],
filePaths: ['/.github', '/.gitlab'],
filesShouldContain: [],
};
51 changes: 22 additions & 29 deletions packages/cli-tool/test/commands/generate/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ const viteTestScenarios: TestScenario[] = [
templateReference: viteTemplateReference,
testData: {
filesShouldExist: [
...gitHubTestData.filesShouldExist,
...bootstrapTestData.filesShouldExist,
...gitHubTestData.filePaths,
...bootstrapTestData.filePaths,
],
filesShouldNotExist: [
...gitHubTestData.filesShouldNotExist,
...bootstrapTestData.filesShouldNotExist,
...gitLabTestData.filePaths,
...tailwindCssTestData.filePaths,
],
filesShouldContain: [
...gitHubTestData.filesShouldContain,
Expand All @@ -48,12 +48,12 @@ const viteTestScenarios: TestScenario[] = [
templateReference: viteTemplateReference,
testData: {
filesShouldExist: [
...gitLabTestData.filesShouldExist,
...tailwindCssTestData.filesShouldExist,
...gitLabTestData.filePaths,
...tailwindCssTestData.filePaths,
],
filesShouldNotExist: [
...gitLabTestData.filesShouldNotExist,
...tailwindCssTestData.filesShouldNotExist,
...gitHubTestData.filePaths,
...bootstrapTestData.filePaths,
],
filesShouldContain: [
...gitLabTestData.filesShouldContain,
Expand All @@ -64,23 +64,18 @@ const viteTestScenarios: TestScenario[] = [
{
options: {
template: 'vite',
versionControl: 'github',
uiFramework: 'bootstrap',
versionControl: 'none',
uiFramework: 'none',
},
templateReference: '',
testData: {
filesShouldExist: [
...gitHubTestData.filesShouldExist,
...bootstrapTestData.filesShouldExist,
],
filesShouldExist: [],
filesShouldNotExist: [
...gitHubTestData.filesShouldNotExist,
...bootstrapTestData.filesShouldNotExist,
],
filesShouldContain: [
...gitHubTestData.filesShouldContain,
...bootstrapTestData.filesShouldContain,
...noVersionControlTestData.filePaths,
...bootstrapTestData.filePaths,
...tailwindCssTestData.filePaths,
],
filesShouldContain: [],
},
},
];
Expand All @@ -94,12 +89,12 @@ const craTestScenarios: TestScenario[] = [
templateReference: craTemplateReference,
testData: {
filesShouldExist: [
...gitHubTestData.filesShouldExist,
...bootstrapTestData.filesShouldExist,
...gitHubTestData.filePaths,
...bootstrapTestData.filePaths,
],
filesShouldNotExist: [
...gitHubTestData.filesShouldNotExist,
...bootstrapTestData.filesShouldNotExist,
...gitLabTestData.filePaths,
...tailwindCssTestData.filePaths,
],
filesShouldContain: [
...gitHubTestData.filesShouldContain,
Expand All @@ -116,15 +111,13 @@ const craTestScenarios: TestScenario[] = [
templateReference: craTemplateReference,
testData: {
filesShouldExist: [
...noVersionControlTestData.filesShouldExist,
...tailwindCssTestData.filesShouldExist,
...tailwindCssTestData.filePaths,
],
filesShouldNotExist: [
...noVersionControlTestData.filesShouldNotExist,
...tailwindCssTestData.filesShouldNotExist,
...noVersionControlTestData.filePaths,
...bootstrapTestData.filePaths,
],
filesShouldContain: [
...noVersionControlTestData.filesShouldContain,
...tailwindCssTestData.filesShouldContain,
],
},
Expand Down
8 changes: 1 addition & 7 deletions packages/cli-tool/test/helpers/test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ export type TestData = {
* the generated project.
* E.g. '/src/assets/stylesheets/application.scss`
*/
filesShouldExist: string[];
/** Path relative to the generated project root folder.
* List files or folders that are expected to NOT be included within
* the generated project.
* E.g. '/src/assets/stylesheets/vendor/bootstrap`
*/
filesShouldNotExist: string[];
filePaths: string[];
/** Path relative to the generated project root folder.
* List what file is expected to contain what string.
* E.g.
Expand Down
31 changes: 28 additions & 3 deletions packages/cli-tool/test/helpers/test-scenario.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import { TestData } from './test-data';

/** TestScenario group several add-ons tests
* into a single generate command execution */
export type TestScenario = {
options: any; // eslint-disable-line @typescript-eslint/no-explicit-any
templateReference: string;
testData: TestData;
testData: {
/** Path relative to the generated project root folder.
* List files or folders that are expected to be included within
* the generated project.
* E.g. '/src/assets/stylesheets/application.scss`
*/
filesShouldExist: string[];
/** Path relative to the generated project root folder.
* List files or folders that are expected to NOT be included within
* the generated project.
* E.g. '/src/assets/stylesheets/vendor/bootstrap`
*/
filesShouldNotExist: string[];
/** Path relative to the generated project root folder.
* List what file is expected to contain what string.
* E.g.
* ```
* {
* path: '/src/assets/stylesheets/application.scss`,
* shouldContainString: 'vendor/bootstrap`,
* }
* ```
*/
filesShouldContain: {
path: string;
shouldContainString: string;
}[];
};
};

0 comments on commit fa93b0b

Please sign in to comment.