-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2477 from codefori/cleanup/seperate_frontend_vitest
Move backend test cases to vitest
- Loading branch information
Showing
29 changed files
with
2,078 additions
and
2,157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
config.json | ||
storage.json |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(``); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.