这是一个测试文件,我在其中从另一个文件导入函数
测试/注册.ts
import http from 'k6/http';
import { sleep, check } from 'k6';
import { getCloudflareToken } from '../GoogleCloud';
export default async function () {
const email = [email protected];
const cf_token = await getCloudflareToken('development');
即使导入正确,我也会不断收到此错误:
ERRO[0000] GoError: The moduleSpecifier "../GoogleCloud" couldn't be found on local disk. Make sure that you've specified the right path to the file.
这是位于根目录中的GoogleCloud.ts文件:
// Import the Secret Manager client and instantiate it:
import { SecretManagerServiceClient } from '@google-cloud/secret-manager';
const client = new SecretManagerServiceClient();
export async function getCloudflareToken(env: string) {
const projectID = env === "development" ? "123" : "456";
const [version] = await client.accessSecretVersion({ name: `projects/${projectID}/secrets/CF_TOKEN/versions/1` });
if (version.payload && version.payload.data) {
return version.payload.data.toString();
} else {
throw new Error("Payload data is missing or undefined.");
}
}
这是package.json:
{
"name": "load-testing",
"version": "1.0.0",
"description": "",
"main": "unauthenticated-users.ts",
"scripts": {
"sign-up": "k6 run tests/sign-up.ts",
"unauthenticated-users": "k6 run --vus 100 --duration 5m tests/unauthenticated-users.ts"
},
"license": "ISC",
"devDependencies": {
"@google-cloud/secret-manager": "^5.0.0",
"@types/k6": "^0.45.1",
"@types/node": "^20.4.8",
"typescript": "^5.1.3"
}
}