Closed sweep-ai[bot] closed 11 months ago
The command:
Run npm test
yielded the following error:
##[error]Process completed with exit code 1.
Here are the logs:
> jekyl-seo-action@1.0.0 test
> cross-env NODE_OPTIONS=--experimental-vm-modules jest
FAIL test/generator.test.js
â—Ź Test suite failed to run
SyntaxError: Unexpected token 'export'
18 | }));
19 |
> 20 | const { generateDescriptions, DescriptionResult, GenerationStatus } = await import("../src/generator");
| ^
21 | const { getModelResponse } = await import("../src/openai-client");
22 | const fs = await import("fs/promises");
23 |
at Runtime.loadEsmModule (node_modules/jest-runtime/build/index.js:510:20)
at test/generator.test.js:20:71
(node:1973) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
/home/runner/work/jekyll-seo-ai-action/jekyll-seo-ai-action/src/generator.js:75
export const generateDescriptions = async (pages) => {
^^^^^^
SyntaxError: Unexpected token 'export'
at new Module (node:internal/vm/module:125:21)
at new SourceTextModule (node:internal/vm/module:291:5)
at Runtime.loadEsmModule (/home/runner/work/jekyll-seo-ai-action/jekyll-seo-ai-action/node_modules/jest-runtime/build/index.js:510:20)
at importModuleDynamically (/home/runner/work/jekyll-seo-ai-action/jekyll-seo-ai-action/node_modules/jest-runtime/build/index.js:518:30)
at importModuleDynamicallyWrapper (node:internal/vm/module:429:15)
at /home/runner/work/jekyll-seo-ai-action/jekyll-seo-ai-action/test/generator.test.js:20:71
Node.js v18.18.2
Done.
No files to generate SEO content were detected in this pull request. -- Jekyll SEO AI Action These changes were automatically generated by Jekyll SEO AI Action.
No files to generate SEO content were detected in this pull request. -- Jekyll SEO AI Action These changes were automatically generated by Jekyll SEO AI Action.
PR Feedback: đź‘Ž
I created this PR to address this rule:
"Implementations should be simple, straightforward, and clean."
Description
This PR addresses the complexity introduced in the
generator.js
file by refactoring theDescriptionResult
class and thegenerateDescription
function. TheerrorDescription
property has been removed from theDescriptionResult
class, and thestatus
property has been simplified to a booleanisGenerated
. Additionally, thegenerateDescription
function has been refactored to break down its functionality into smaller, more focused functions for improved readability and maintainability.Summary
errorDescription
property from theDescriptionResult
class and simplified thestatus
property to a booleanisGenerated
.generateDescription
function to break down its functionality into smaller functions:getFrontMatter
andgetDescription
.generateDescription
function to use the new smaller functions and return a newDescriptionResult
with the page, description, andisGenerated
status.