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

Move backend test cases to vitest #2477

Merged
merged 35 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
98be3a1
comprehensive connection tests for the connection
worksofliam Jan 16, 2025
9b85545
Attempt to setup CI
worksofliam Jan 16, 2025
ddbbe1b
Add environment variables for CI tests in workflow configuration
worksofliam Jan 16, 2025
7b41a8f
Add test command to CI workflow for improved testing coverage
worksofliam Jan 16, 2025
ba03775
Initial content tests
worksofliam Jan 16, 2025
cf97f26
Refactor test names for consistency in content tests
worksofliam Jan 16, 2025
f9000dc
Add missing test cases for content validation
worksofliam Jan 16, 2025
b625eab
Add additional test cases for edge scenarios in content validation
worksofliam Jan 16, 2025
bf57879
Add debug and encoding tests
worksofliam Jan 16, 2025
470d1de
Merge branch 'cleanup/seperate_frontend' into cleanup/seperate_fronte…
worksofliam Jan 16, 2025
e6f2a5d
Register new components in global setup for testing
worksofliam Jan 16, 2025
d1e890a
Merge branch 'cleanup/seperate_frontend' into cleanup/seperate_fronte…
worksofliam Jan 16, 2025
4a0efe9
Merge branch 'cleanup/seperate_frontend' into cleanup/seperate_fronte…
worksofliam Jan 16, 2025
21472c4
Enable some concurrency in the test suites
worksofliam Jan 16, 2025
526d243
Create JSON config stores for faster loading on second time connect
worksofliam Jan 16, 2025
2df56a5
Remove unused test suites from the testing index
worksofliam Jan 16, 2025
6c3bad7
Move tests
worksofliam Jan 16, 2025
f724d3f
Remove backend test cases from encodings
worksofliam Jan 16, 2025
342f7d3
Merge branch 'cleanup/seperate_frontend' into cleanup/seperate_fronte…
worksofliam Jan 17, 2025
7d5e800
Merge branch 'cleanup/seperate_frontend' into cleanup/seperate_fronte…
worksofliam Jan 17, 2025
4bb2610
Remove unused test configuration and storage JSON files
worksofliam Jan 17, 2025
c3d6d5a
Swap over component tests to vitest
worksofliam Jan 17, 2025
8187bee
Move over filter tests
worksofliam Jan 17, 2025
4dc7e3a
Move errors to vitest
worksofliam Jan 17, 2025
1c2bbc6
Move search tests
worksofliam Jan 17, 2025
85b5e3b
No more global setup for the connection since not all suites require …
worksofliam Jan 17, 2025
092c5db
Use it over test
worksofliam Jan 17, 2025
cdd86d4
Increase timeout for 'Listing objects with variants' test
worksofliam Jan 17, 2025
043822f
Increase timeout for Content Tests setup
worksofliam Jan 17, 2025
ea6bfc0
Tests run concurrently
worksofliam Jan 17, 2025
c9112f1
Merge branch 'cleanup/seperate_frontend' into cleanup/seperate_fronte…
worksofliam Jan 21, 2025
ff7f456
Update content.test.ts
worksofliam Jan 22, 2025
4b9c7aa
Merge branch 'master' into cleanup/seperate_frontend_vitest
worksofliam Jan 22, 2025
005aeed
Fix base storage
worksofliam Jan 22, 2025
19a2673
Use variable for timeouts
worksofliam Jan 22, 2025
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
24 changes: 24 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
pull_request:
paths:
- 'src/api/**'

jobs:
tester:
environment: testing_environment
name: Test runner
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm run test
env:
VITE_SERVER: ${{ secrets.VITE_SERVER }}
VITE_DB_USER: ${{ secrets.VITE_DB_USER }}
VITE_DB_PASS: ${{ secrets.VITE_DB_PASS }}
VITE_DB_PORT: ${{ secrets.VITE_DB_PORT }}
3 changes: 2 additions & 1 deletion src/api/.env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
VITE_SERVER=
VITE_DB_USER=
VITE_DB_PASS=
VITE_DB_PORT=22
VITE_DB_PORT=22
#VITE_CONNECTION_TIMEOUT=25000
4 changes: 2 additions & 2 deletions src/api/IBMi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,12 +1098,12 @@ export default class IBMi {
*/
getTempRemote(key: string) {
if (this.tempRemoteFiles[key] !== undefined) {
console.log(`Using existing temp: ${this.tempRemoteFiles[key]}`);
// console.log(`Using existing temp: ${this.tempRemoteFiles[key]}`);
return this.tempRemoteFiles[key];
} else
if (this.config) {
let value = path.posix.join(this.config.tempDir, `vscodetemp-${Tools.makeid()}`);
console.log(`Using new temp: ${value}`);
// console.log(`Using new temp: ${value}`);
this.tempRemoteFiles[key] = value;
return value;
}
Expand Down
2 changes: 2 additions & 0 deletions src/api/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config.json
storage.json
10 changes: 0 additions & 10 deletions src/api/tests/a.test.ts

This file was deleted.

51 changes: 0 additions & 51 deletions src/api/tests/config.json

This file was deleted.

86 changes: 86 additions & 0 deletions src/api/tests/connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import IBMi from "../IBMi";
import { CodeForIStorage } from "../configuration/storage/CodeForIStorage";
import { CustomQSh } from "../components/cqsh";
import path from "path";
import { CopyToImport } from "../components/copyToImport";
import { GetMemberInfo } from "../components/getMemberInfo";
import { GetNewLibl } from "../components/getNewLibl";
import { extensionComponentRegistry } from "../components/manager";
import { JsonConfig, JsonStorage } from "./testConfigSetup";

export const testStorage = new JsonStorage();
const testConfig = new JsonConfig();

export const CONNECTION_TIMEOUT = process.env.VITE_CONNECTION_TIMEOUT ? parseInt(process.env.VITE_CONNECTION_TIMEOUT) : 25000;

const ENV_CREDS = {
host: process.env.VITE_SERVER || `localhost`,
user: process.env.VITE_DB_USER,
password: process.env.VITE_DB_PASS,
port: parseInt(process.env.VITE_DB_PORT || `22`)
}

export async function newConnection() {
const virtualStorage = testStorage;

IBMi.GlobalStorage = new CodeForIStorage(virtualStorage);
IBMi.connectionManager.configMethod = testConfig;

await testStorage.load();
await testConfig.load();

const conn = new IBMi();

const customQsh = new CustomQSh();
const cqshPath = path.join(__dirname, `..`, `components`, `cqsh`, `cqsh`);
customQsh.setLocalAssetPath(cqshPath);

const testingId = `testing`;
extensionComponentRegistry.registerComponent(testingId, customQsh);
extensionComponentRegistry.registerComponent(testingId, new GetNewLibl());
extensionComponentRegistry.registerComponent(testingId, new GetMemberInfo());
extensionComponentRegistry.registerComponent(testingId, new CopyToImport());

const creds = {
host: ENV_CREDS.host!,
name: `testsystem`,
username: ENV_CREDS.user!,
password: ENV_CREDS.password!,
port: ENV_CREDS.port
};

// Override this so not to spam the console.
conn.appendOutput = (data) => {};

const result = await conn.connect(
creds,
{
message: (type: string, message: string) => {
// console.log(`${type.padEnd(10)} ${message}`);
},
progress: ({message}) => {
// console.log(`PROGRESS: ${message}`);
},
uiErrorHandler: async (connection, code, data) => {
console.log(`Connection warning: ${code}: ${JSON.stringify(data)}`);
return false;
},
}
);

if (!result.success) {
throw new Error(`Failed to connect to IBMi`);
}

return conn;
}

export function disposeConnection(conn?: IBMi) {
if (!conn) {
return;
}

conn.dispose();
testStorage.save();
testConfig.save();
}
11 changes: 0 additions & 11 deletions src/api/tests/env.ts

This file was deleted.

59 changes: 0 additions & 59 deletions src/api/tests/globalSetup.ts

This file was deleted.

18 changes: 18 additions & 0 deletions src/api/tests/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { TestProject } from "vitest/node";
import { disposeConnection, newConnection, testStorage } from "./connection";

export async function setup(project: TestProject) {
// You might pre-connect to simply create the configuration files.
// When the config files exist, it makes future connections just slightly faster.
// Mostly useful during the CI stage.
if (!testStorage.exists()) {
console.log(``);
console.log(`Testing connection before tests run since configs do not exist.`);

const conn = await newConnection();
disposeConnection(conn);

console.log(`Testing connection complete. Configs written.`);
console.log(``);
}
}
11 changes: 0 additions & 11 deletions src/api/tests/state.ts

This file was deleted.

38 changes: 0 additions & 38 deletions src/api/tests/storage.json

This file was deleted.

Loading
Loading