Skip to content

Commit

Permalink
Move the tests into individual files for parallelization (#54)
Browse files Browse the repository at this point in the history
# Pull Request

## 📖 Description

<!--- Provide some background and a description of your work. -->
This work moves the individual playwright tests to their own files and leverages the setup from #53 so that temp files have their own uuid.

Edit: This may seem like a lot of duplication, but I believe it is preferable to attempting to optimize too soon as we don't yet know what extra component-specific tests will be required.

### 🎫 Issues

<!---
List and link relevant issues here using the keyword "closes"
if this PR will close an issue, eg. closes #411
-->
Continues work on #31

## 👩‍💻 Reviewer Notes

<!---
Provide some notes for reviewers to help them provide targeted feedback and testing.
-->
No changes, only file moves.

## ✅ Checklist

### General

<!--- Review the list and put an x in the boxes that apply. -->

- [ ] I have added tests for my changes.
- [x] I have tested my changes.
- [ ] I have updated the project documentation to reflect my changes.

## ⏭ Next Steps

<!---
If there is relevant follow-up work to this PR, please list any existing issues or provide brief descriptions of what you would like to do next.
-->
- Continue work on #31
  • Loading branch information
janechu committed May 23, 2022
1 parent f96a1d2 commit 0142cb5
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 303 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Move the tests into individual files for parallelization",
"packageName": "@microsoft/fast-cli",
"email": "7559015+janechu@users.noreply.github.com",
"dependentChangeType": "none"
}
303 changes: 0 additions & 303 deletions packages/fast-cli/src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,307 +211,4 @@ test.describe("CLI", () => {
).not.toThrow();
});
});
test.describe("add-foundation-component", () => {
test.describe("blank", () => {
test.beforeAll(() => {
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:init`);
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:add-foundation-component:blank`);
});
test.afterAll(() => {
teardown(tempDir, tempComponentDir);
});
test("should copy files from the template", () => {
let files: Array<string> = [];

function testGeneratedFiles(folderName: string) {
const tempDirContents = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName));
const tempDirContentsWithFileTypes = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName), {
withFileTypes: true
});

for (let i = 0, contentLength = tempDirContents.length; i < contentLength; i++) {
if (tempDirContentsWithFileTypes[i].isDirectory()) {
testGeneratedFiles(tempDirContents[i]);
} else {
files.push(
folderName
? `${folderName}/${tempDirContents[i]}`
: tempDirContents[i]
);
}
}
}

testGeneratedFiles("");
expect(files).toEqual(expectedGeneratedComponentTemplateFiles);
});
test("should be able to run the build", () => {
expect(
() => {
execSync(`cd ${tempDir} && npm run build`);
}
).not.toThrow();
});
});
test.describe("badge", () => {
test.beforeAll(() => {
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:init`);
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:add-foundation-component:badge`);
});
test.afterAll(() => {
teardown(tempDir, tempComponentDir);
});
test("should copy files from the template", () => {
let files: Array<string> = [];

function testGeneratedFiles(folderName: string) {
const tempDirContents = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName));
const tempDirContentsWithFileTypes = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName), {
withFileTypes: true
});

for (let i = 0, contentLength = tempDirContents.length; i < contentLength; i++) {
if (tempDirContentsWithFileTypes[i].isDirectory()) {
testGeneratedFiles(tempDirContents[i]);
} else {
files.push(
folderName
? `${folderName}/${tempDirContents[i]}`
: tempDirContents[i]
);
}
}
}

testGeneratedFiles("");
expect(files).toEqual(expectedGeneratedComponentTemplateFiles);
});
test("should be able to run the build", () => {
expect(
() => {
execSync(`cd ${tempDir} && npm run build`);
}
).not.toThrow();
});
});
test.describe("disclosure", () => {
test.beforeAll(() => {
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:init`);
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:add-foundation-component:disclosure`);
});
test.afterAll(() => {
teardown(tempDir, tempComponentDir);
});
test("should copy files from the template", () => {
let files: Array<string> = [];

function testGeneratedFiles(folderName: string) {
const tempDirContents = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName));
const tempDirContentsWithFileTypes = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName), {
withFileTypes: true
});

for (let i = 0, contentLength = tempDirContents.length; i < contentLength; i++) {
if (tempDirContentsWithFileTypes[i].isDirectory()) {
testGeneratedFiles(tempDirContents[i]);
} else {
files.push(
folderName
? `${folderName}/${tempDirContents[i]}`
: tempDirContents[i]
);
}
}
}

testGeneratedFiles("");
expect(files).toEqual(expectedGeneratedComponentTemplateFiles);
});
test("should be able to run the build", () => {
expect(
() => {
execSync(`cd ${tempDir} && npm run build`);
}
).not.toThrow();
});
});
test.describe("card", () => {
test.beforeAll(() => {
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:init`);
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:add-foundation-component:card`);
});
test.afterAll(() => {
teardown(tempDir, tempComponentDir);
});
test("should copy files from the template", () => {
let files: Array<string> = [];

function testGeneratedFiles(folderName: string) {
const tempDirContents = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName));
const tempDirContentsWithFileTypes = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName), {
withFileTypes: true
});

for (let i = 0, contentLength = tempDirContents.length; i < contentLength; i++) {
if (tempDirContentsWithFileTypes[i].isDirectory()) {
testGeneratedFiles(tempDirContents[i]);
} else {
files.push(
folderName
? `${folderName}/${tempDirContents[i]}`
: tempDirContents[i]
);
}
}
}

testGeneratedFiles("");
expect(files).toEqual(expectedGeneratedComponentTemplateFiles);
});
test("should be able to run the build", () => {
expect(
() => {
execSync(`cd ${tempDir} && npm run build`);
}
).not.toThrow();
});
});
test.describe("dialog", () => {
test.beforeAll(() => {
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:init`);
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:add-foundation-component:dialog`);
});
test.afterAll(() => {
teardown(tempDir, tempComponentDir);
});
test("should copy files from the template", () => {
let files: Array<string> = [];

function testGeneratedFiles(folderName: string) {
const tempDirContents = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName));
const tempDirContentsWithFileTypes = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName), {
withFileTypes: true
});

for (let i = 0, contentLength = tempDirContents.length; i < contentLength; i++) {
if (tempDirContentsWithFileTypes[i].isDirectory()) {
testGeneratedFiles(tempDirContents[i]);
} else {
files.push(
folderName
? `${folderName}/${tempDirContents[i]}`
: tempDirContents[i]
);
}
}
}

testGeneratedFiles("");
expect(files).toEqual(expectedGeneratedComponentTemplateFiles);
});
test("should be able to run the build", () => {
expect(
() => {
execSync(`cd ${tempDir} && npm run build`);
}
).not.toThrow();
});
});
test.describe("number-field", () => {
test.beforeAll(() => {
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:init`);
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:add-foundation-component:number-field`);
});
test.afterAll(() => {
teardown(tempDir, tempComponentDir);
});
test("should copy files from the template", () => {
let files: Array<string> = [];

function testGeneratedFiles(folderName: string) {
const tempDirContents = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName));
const tempDirContentsWithFileTypes = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName), {
withFileTypes: true
});

for (let i = 0, contentLength = tempDirContents.length; i < contentLength; i++) {
if (tempDirContentsWithFileTypes[i].isDirectory()) {
testGeneratedFiles(tempDirContents[i]);
} else {
files.push(
folderName
? `${folderName}/${tempDirContents[i]}`
: tempDirContents[i]
);
}
}
}

testGeneratedFiles("");
expect(files).toEqual(expectedGeneratedComponentTemplateFiles);
});
test("should be able to run the build", () => {
expect(
() => {
execSync(`cd ${tempDir} && npm run build`);
}
).not.toThrow();
});
});
test.describe("search", () => {
test.beforeAll(() => {
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:init`);
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:add-foundation-component:search`);
});
test.afterAll(() => {
teardown(tempDir, tempComponentDir);
});
test("should copy files from the template", () => {
let files: Array<string> = [];

function testGeneratedFiles(folderName: string) {
const tempDirContents = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName));
const tempDirContentsWithFileTypes = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName), {
withFileTypes: true
});

for (let i = 0, contentLength = tempDirContents.length; i < contentLength; i++) {
if (tempDirContentsWithFileTypes[i].isDirectory()) {
testGeneratedFiles(tempDirContents[i]);
} else {
files.push(
folderName
? `${folderName}/${tempDirContents[i]}`
: tempDirContents[i]
);
}
}
}

testGeneratedFiles("");
expect(files).toEqual(expectedGeneratedComponentTemplateFiles);
});
test("should be able to run the build", () => {
expect(
() => {
execSync(`cd ${tempDir} && npm run build`);
}
).not.toThrow();
});
});
});
});
59 changes: 59 additions & 0 deletions packages/fast-cli/src/components/badge/template.pw.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { expect, test } from "@playwright/test";
import { execSync } from "child_process";
import path from "path";
import fs from "fs-extra";
import {
expectedGeneratedComponentTemplateFiles,
setup,
teardown,
getTempDir,
getTempComponentDir,
} from "../../test/helpers.js";

const uuid: string = "badge";
const tempDir: string = getTempDir(uuid);
const tempComponentDir: string = getTempComponentDir(uuid);

test.describe(`CLI add-foundation-component ${uuid}`, () => {
test.beforeAll(() => {
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:init`);
setup(tempDir, tempComponentDir);
execSync(`cd ${tempDir} && npm run fast:add-foundation-component:${uuid}`);
});
test.afterAll(() => {
teardown(tempDir, tempComponentDir);
});
test("should copy files from the template", () => {
let files: Array<string> = [];

function testGeneratedFiles(folderName: string) {
const tempDirContents = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName));
const tempDirContentsWithFileTypes = fs.readdirSync(path.resolve(tempDir, "src/components/test-component", folderName), {
withFileTypes: true
});

for (let i = 0, contentLength = tempDirContents.length; i < contentLength; i++) {
if (tempDirContentsWithFileTypes[i].isDirectory()) {
testGeneratedFiles(tempDirContents[i]);
} else {
files.push(
folderName
? `${folderName}/${tempDirContents[i]}`
: tempDirContents[i]
);
}
}
}

testGeneratedFiles("");
expect(files).toEqual(expectedGeneratedComponentTemplateFiles);
});
test("should be able to run the build", () => {
expect(
() => {
execSync(`cd ${tempDir} && npm run build`);
}
).not.toThrow();
});
});

0 comments on commit 0142cb5

Please sign in to comment.