Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(aws): make buildYmlSpec generic #206

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions packages/plugins/aws-device-farm/src/buildYmlSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ done;`,
createFile: (code: string, filePath: string) => [
`echo ${Buffer.from(code).toString("base64")} | base64 -d > ${filePath}`,
],
MOVE_RESULTS_TO_ARTIFACTS: [
"mv result*.json $DEVICEFARM_LOG_DIR",
"mv *.mp4 $DEVICEFARM_LOG_DIR || true",
],
};

export const buildYmlSpec = ({
Expand All @@ -59,22 +63,13 @@ export const buildYmlSpec = ({
android_test_host: "amazon_linux_2",
phases: {
install: {
commands: [
...Commands.INSTALL_NODE,
...Commands.UNPACKAGE_TEST_PACKAGE,
...(installCommands || []),
],
commands: [...(installCommands || [])],
},
pre_test: {
commands: [...(preTestCommands || [])],
},
test: {
commands: [
...Commands.NAVIGATE_TO_TEST_SOURCE_CODE,
...testCommands,
"mv result*.json $DEVICEFARM_LOG_DIR",
"mv *.mp4 $DEVICEFARM_LOG_DIR || true",
],
commands: [...testCommands],
},
post_test: {
commands: postTestCommands,
Expand Down
31 changes: 25 additions & 6 deletions packages/plugins/aws-device-farm/src/createTestSpecFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@ import fs from "fs";
import { buildYmlSpec, Commands } from "./buildYmlSpec";
import { TMP_FOLDER } from "./TMP_FOLDER";

const buildAppiumYmlSpec = (commands: {
testCommands: string[];
postTestCommands?: string[];
installCommands?: string[];
preTestCommands?: string[];
}) =>
buildYmlSpec({
...commands,
installCommands: [
...Commands.INSTALL_NODE,
...Commands.UNPACKAGE_TEST_PACKAGE,
...Commands.INSTALL_APPIUM,
...(commands.installCommands || []),
],
preTestCommands: [...Commands.START_APPIUM, ...(commands.preTestCommands || [])],
testCommands: [
...Commands.NAVIGATE_TO_TEST_SOURCE_CODE,
...commands.testCommands,
...Commands.MOVE_RESULTS_TO_ARTIFACTS,
],
});

export const getSingleTestFileYml = ({
testFile,
postTestCommand = "echo 'Tests are done!",
Expand All @@ -11,18 +33,15 @@ export const getSingleTestFileYml = ({
}) => {
const testCode = fs.readFileSync(testFile).toString();

return buildYmlSpec({
installCommands: [...Commands.INSTALL_APPIUM],
preTestCommands: [...Commands.START_APPIUM],
return buildAppiumYmlSpec({
testCommands: [...Commands.createFile(testCode, "runTest.ts"), "npx ts-node runTest.ts"],
postTestCommands: [postTestCommand].filter(Boolean),
});
};

export const getTestCommandYml = ({ testCommand }: { testCommand: string }) => {
return buildYmlSpec({
preTestCommands: [...Commands.START_APPIUM],
installCommands: [...Commands.INSTALL_APPIUM, "npm install --global yarn"],
return buildAppiumYmlSpec({
installCommands: ["npm install --global yarn"],
testCommands: ["yarn", testCommand],
});
};
Expand Down
Loading