From a9701f9a3cdc21465024464a1ca3c82ff47e7ce0 Mon Sep 17 00:00:00 2001 From: Christoph Pirkl Date: Tue, 12 Sep 2023 10:30:57 +0200 Subject: [PATCH] #139: Convert `extensionForTesting` to JavaScript to speedup tests (#140) --- doc/changes/changes_0.5.2.md | 4 +++ pkg/extensionController/controller_test.go | 2 +- ...late.ts => extensionForTestingTemplate.js} | 26 +++++++++---------- .../extensionForTesting/package.json | 21 +++++++-------- .../extensionForTesting/tsconfig.json | 16 ------------ .../testExtensionBuilder.go | 11 ++------ 6 files changed, 29 insertions(+), 51 deletions(-) rename pkg/integrationTesting/extensionForTesting/{extensionForTestingTemplate.ts => extensionForTestingTemplate.js} (50%) delete mode 100644 pkg/integrationTesting/extensionForTesting/tsconfig.json diff --git a/doc/changes/changes_0.5.2.md b/doc/changes/changes_0.5.2.md index c27f6333..e9d328d7 100644 --- a/doc/changes/changes_0.5.2.md +++ b/doc/changes/changes_0.5.2.md @@ -10,6 +10,10 @@ This release updates the upload process for the extension registry to verify tha * #129: Added verification for extension URLs before uploading to registry +## Refactoring + +* #139: Converted `extensionForTesting` to JavaScript to speedup tests + ## Dependency Updates ### Extension Integration Tests Library diff --git a/pkg/extensionController/controller_test.go b/pkg/extensionController/controller_test.go index cfadeba8..a2d7f1db 100644 --- a/pkg/extensionController/controller_test.go +++ b/pkg/extensionController/controller_test.go @@ -119,7 +119,7 @@ var errorTests = []errorTest{ {testName: "generic", throwCommand: "throw Error(`mock error from js`);", expectedStatus: -1}, {testName: "internal server error", throwCommand: "throw new InternalServerError(`mock error from js`);", expectedStatus: -1}, {testName: "bad request", throwCommand: "throw new BadRequestError(`mock error from js`);", expectedStatus: 400}, - {testName: "null pointer", throwCommand: `({}).a.b; throw Error("mock");`, expectedStatus: -1, expectedMessage: "TypeError: Cannot read property 'b' of undefined"}, + {testName: "null pointer", throwCommand: `({}).a.b; throw Error("mock");`, expectedStatus: -1, expectedMessage: "TypeError: Cannot read property 'b' of undefined"}, } func (suite *ControllerUTestSuite) TestGetAllInstallationsFails() { diff --git a/pkg/integrationTesting/extensionForTesting/extensionForTestingTemplate.ts b/pkg/integrationTesting/extensionForTesting/extensionForTestingTemplate.js similarity index 50% rename from pkg/integrationTesting/extensionForTesting/extensionForTestingTemplate.ts rename to pkg/integrationTesting/extensionForTesting/extensionForTestingTemplate.js index 4d69538e..d7b4b58e 100644 --- a/pkg/integrationTesting/extensionForTesting/extensionForTestingTemplate.ts +++ b/pkg/integrationTesting/extensionForTesting/extensionForTestingTemplate.js @@ -1,43 +1,41 @@ import { - BadRequestError, Context, ExaMetadata, ExasolExtension, - Installation, - Instance, InternalServerError, Parameter, ParameterValues, - UpgradeResult, + BadRequestError, + InternalServerError, registerExtension } from "@exasol/extension-manager-interface"; -function createExtension(): ExasolExtension { +function createExtension() { return { name: "MyDemoExtension", description: "An extension for testing.", category: "Demo category", installableVersions: [{ name: "0.1.0", latest: true, deprecated: false }], bucketFsUploads: $UPLOADS$, - install(context: Context, version: string) { + install(context, version) { $INSTALL_EXTENSION$ }, - addInstance(context: Context, version: string, params: ParameterValues): Instance { + addInstance(context, version, params) { $ADD_INSTANCE$ }, - findInstallations(context: Context, metadata: ExaMetadata): Installation[] { + findInstallations(context, metadata) { $FIND_INSTALLATIONS$ }, - findInstances(context: Context, version: string): Instance[] { + findInstances(context, version) { $FIND_INSTANCES$ }, - uninstall(context: Context, version: string): void { + uninstall(context, version) { $UNINSTALL_EXTENSION$ }, - upgrade(context: Context): UpgradeResult { + upgrade(context) { $UPGRADE_EXTENSION$ }, - deleteInstance(context: Context, extensionVersion: string, instanceId: string): void { + deleteInstance(context, extensionVersion, instanceId) { $DELETE_INSTANCE$ }, - getInstanceParameters(context: Context, version: string): Parameter[] { + getInstanceParameters(context, version) { $GET_INSTANCE_PARAMETER_DEFINITIONS$ }, - readInstanceParameterValues(context: Context, extensionVersion: string, instanceId: string): ParameterValues { + readInstanceParameterValues(context, extensionVersion, instanceId) { return undefined; } } diff --git a/pkg/integrationTesting/extensionForTesting/package.json b/pkg/integrationTesting/extensionForTesting/package.json index db934787..a8818f5e 100644 --- a/pkg/integrationTesting/extensionForTesting/package.json +++ b/pkg/integrationTesting/extensionForTesting/package.json @@ -1,13 +1,12 @@ { - "scripts": { - "build": "tsc --build && esbuild dist/extensionForTesting.js --bundle --outfile=dist.js --target=es6", - "clean": "tsc --build --clean" - }, - "dependencies": { - "@exasol/extension-manager-interface": "0.3.0" - }, - "devDependencies": { - "esbuild": "^0.18.16", - "typescript": "^5.1.6" - } + "scripts": { + "build": "esbuild extensionForTesting.js --bundle --outfile=dist.js --target=es6", + "clean": "rm -rf dist/" + }, + "dependencies": { + "@exasol/extension-manager-interface": "0.3.0" + }, + "devDependencies": { + "esbuild": "^0.18.16" + } } \ No newline at end of file diff --git a/pkg/integrationTesting/extensionForTesting/tsconfig.json b/pkg/integrationTesting/extensionForTesting/tsconfig.json deleted file mode 100644 index 0e5f728a..00000000 --- a/pkg/integrationTesting/extensionForTesting/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "compilerOptions": { - "noImplicitAny": true, - "noEmitOnError": true, - "removeComments": false, - "sourceMap": true, - "target": "es6", - "outDir": "dist/", - "declaration": true, - "moduleResolution": "node", - "esModuleInterop": true, - }, - "include": [ - "extensionForTesting.ts" - ] -} diff --git a/pkg/integrationTesting/testExtensionBuilder.go b/pkg/integrationTesting/testExtensionBuilder.go index 73d00fdc..4ccf7e21 100644 --- a/pkg/integrationTesting/testExtensionBuilder.go +++ b/pkg/integrationTesting/testExtensionBuilder.go @@ -107,20 +107,13 @@ func (builder *TestExtensionBuilder) WithBucketFsUpload(upload BucketFsUploadPar return builder } -//go:embed extensionForTesting/tsconfig.json -var tscConfig []byte - func (builder TestExtensionBuilder) Build() *BuiltExtension { workDir := builder.createWorkDir() err := os.WriteFile(path.Join(workDir, "package.json"), []byte(builder.createPackageJsonContent()), 0600) if err != nil { panic(err) } - err = os.WriteFile(path.Join(workDir, "extensionForTesting.ts"), []byte(builder.createExtensionTsContent()), 0600) - if err != nil { - panic(err) - } - err = os.WriteFile(path.Join(workDir, "tsconfig.json"), tscConfig, 0600) + err = os.WriteFile(path.Join(workDir, "extensionForTesting.js"), []byte(builder.createExtensionTsContent()), 0600) if err != nil { panic(err) } @@ -146,7 +139,7 @@ func (builder TestExtensionBuilder) createPackageJsonContent() string { return strings.Replace(packageJsonTemplate, "$EXTENSION_API_VERSION$", builder.extensionApiVersion, 1) } -//go:embed extensionForTesting/extensionForTestingTemplate.ts +//go:embed extensionForTesting/extensionForTestingTemplate.js var extensionTemplate string func (builder TestExtensionBuilder) createExtensionTsContent() string {