diff --git a/src/api/IBMi.ts b/src/api/IBMi.ts index 13cce21c5..a30afc0db 100644 --- a/src/api/IBMi.ts +++ b/src/api/IBMi.ts @@ -1097,12 +1097,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; } diff --git a/src/api/tests/globalSetup.ts b/src/api/tests/globalSetup.ts index a76a7f996..1c5c6440d 100644 --- a/src/api/tests/globalSetup.ts +++ b/src/api/tests/globalSetup.ts @@ -1,11 +1,8 @@ import assert from "assert"; import IBMi from "../IBMi"; import { ENV_CREDS } from "./env"; -import { getConnection, setConnection } from "./state"; import { afterAll, beforeAll, expect } from "vitest"; import { CodeForIStorage } from "../configuration/storage/CodeForIStorage"; -import { VirtualConfig } from "../configuration/config/VirtualConfig"; -import { VirtualStorage } from "../configuration/storage/BaseStorage"; import { CustomQSh } from "../components/cqsh"; import path from "path"; import { CopyToImport } from "../components/copyToImport"; @@ -71,28 +68,8 @@ export async function newConnection() { return conn; } -beforeAll(async () => { - const virtualStorage = testStorage; - - IBMi.GlobalStorage = new CodeForIStorage(virtualStorage); - IBMi.connectionManager.configMethod = testConfig; - - await testStorage.load(); - await testConfig.load(); - - const conn = await newConnection(); - - setConnection(conn); -}, 10000000); - -afterAll(async () => { - const conn = getConnection(); - - if (conn) { - await conn.dispose(); - await testStorage.save(); - await testConfig.save(); - } else { - assert.fail(`Connection was not set`); - } -}) \ No newline at end of file +export function disposeConnection(conn: IBMi) { + conn.dispose(); + testStorage.save(); + testConfig.save(); +} \ No newline at end of file diff --git a/src/api/tests/state.ts b/src/api/tests/state.ts deleted file mode 100644 index 6ed5f0439..000000000 --- a/src/api/tests/state.ts +++ /dev/null @@ -1,11 +0,0 @@ -import IBMi from "../IBMi"; - -let connection: IBMi; - -export function setConnection(conn: IBMi) { - connection = conn; -} - -export function getConnection() { - return connection!; -} \ No newline at end of file diff --git a/src/api/tests/suites/components.test.ts b/src/api/tests/suites/components.test.ts index 9e3246422..7feac8ffb 100644 --- a/src/api/tests/suites/components.test.ts +++ b/src/api/tests/suites/components.test.ts @@ -1,14 +1,21 @@ -import { describe, it, expect } from 'vitest'; +import { describe, it, expect, beforeAll, afterAll } from 'vitest'; import { GetMemberInfo } from '../../components/getMemberInfo'; import { GetNewLibl } from '../../components/getNewLibl'; import { Tools } from '../../Tools'; -import { getConnection } from '../state'; +import IBMi from '../../IBMi'; +import { disposeConnection, newConnection } from '../globalSetup'; describe('Component Tests', () => { + let connection: IBMi + beforeAll(async () => { + connection = await newConnection(); + }) + afterAll(async () => { + disposeConnection(connection); + }); it('Get new libl', async () => { - const connection = getConnection(); const component = connection.getComponent(GetNewLibl.ID); if (component) { @@ -20,7 +27,6 @@ describe('Component Tests', () => { }); it('Check getMemberInfo', async () => { - const connection = getConnection(); const component = connection?.getComponent(GetMemberInfo.ID)!; expect(component).toBeTruthy(); diff --git a/src/api/tests/suites/connection.test.ts b/src/api/tests/suites/connection.test.ts index 6d4e5a9a2..9b7bfee90 100644 --- a/src/api/tests/suites/connection.test.ts +++ b/src/api/tests/suites/connection.test.ts @@ -1,12 +1,21 @@ -import { expect, test, describe } from 'vitest' -import { getConnection } from '../state' +import { expect, test, describe, afterAll, beforeAll, it } from 'vitest' import { Tools } from '../../Tools'; +import { disposeConnection, newConnection } from '../globalSetup'; +import IBMi from '../../IBMi'; +import { getJavaHome } from '../../configuration/DebugConfiguration'; describe(`connection tests`, {concurrent: true}, () => { - test('sendCommand', async () => { - const connection = getConnection(); + let connection: IBMi + beforeAll(async () => { + connection = await newConnection(); + }) + + afterAll(async () => { + disposeConnection(connection); + }); + test('sendCommand', async () => { const result = await connection.sendCommand({ command: `echo "Hello world"`, }); @@ -16,8 +25,6 @@ describe(`connection tests`, {concurrent: true}, () => { }) test('sendCommand with home directory', async () => { - const connection = getConnection(); - const resultA = await connection.sendCommand({ command: `pwd`, directory: `/QSYS.LIB` @@ -44,8 +51,6 @@ describe(`connection tests`, {concurrent: true}, () => { }); test('sendCommand with environment variables', async () => { - const connection = getConnection(); - const result = await connection.sendCommand({ command: `echo "$vara $varB $VARC"`, env: { @@ -60,8 +65,6 @@ describe(`connection tests`, {concurrent: true}, () => { }); test('getTempRemote', () => { - const connection = getConnection(); - const fileA = connection.getTempRemote(`/some/file`); const fileB = connection.getTempRemote(`/some/badfile`); const fileC = connection.getTempRemote(`/some/file`); @@ -71,8 +74,6 @@ describe(`connection tests`, {concurrent: true}, () => { }) test('parseMemberPath (simple)', () => { - const connection = getConnection(); - const memberA = connection.parserMemberPath(`/thelib/thespf/thembr.mbr`); expect(memberA?.asp).toBeUndefined(); @@ -84,8 +85,6 @@ describe(`connection tests`, {concurrent: true}, () => { }) test('parseMemberPath (ASP)', () => { - const connection = getConnection(); - const memberA = connection.parserMemberPath(`/theasp/thelib/thespf/thembr.mbr`); expect(memberA?.asp).toBe(`THEASP`); @@ -97,8 +96,6 @@ describe(`connection tests`, {concurrent: true}, () => { }) test('parseMemberPath (no root)', () => { - const connection = getConnection(); - const memberA = connection.parserMemberPath(`thelib/thespf/thembr.mbr`); expect(memberA?.asp).toBe(undefined); @@ -110,8 +107,6 @@ describe(`connection tests`, {concurrent: true}, () => { }); test('parseMemberPath (no extension)', () => { - const connection = getConnection(); - const memberA = connection.parserMemberPath(`/thelib/thespf/thembr`); expect(memberA?.asp).toBe(undefined); @@ -127,16 +122,12 @@ describe(`connection tests`, {concurrent: true}, () => { }); test('parseMemberPath (invalid length)', () => { - const connection = getConnection(); - expect( () => { connection.parserMemberPath(`/thespf/thembr.mbr`) } ).toThrow(`Invalid path: /thespf/thembr.mbr. Use format LIB/SPF/NAME.ext`); }); test('runCommand (ILE)', async () => { - const connection = getConnection(); - const result = await connection.runCommand({ command: `DSPJOB OPTION(*DFNA)`, environment: `ile` @@ -147,7 +138,7 @@ describe(`connection tests`, {concurrent: true}, () => { }) test('runCommand (ILE, with error)', async () => { - const result = await getConnection().runCommand({ + const result = await connection.runCommand({ command: `CHKOBJ OBJ(QSYS/NOEXIST) OBJTYPE(*DTAARA)`, noLibList: true }); @@ -156,9 +147,7 @@ describe(`connection tests`, {concurrent: true}, () => { expect(result?.stderr).toBeTruthy(); }); - test('runCommand (ILE, custom library list)', async () => { - const connection = getConnection(); - const config = connection.getConfig(); + test('runCommand (ILE, custom library list)', async () => { const config = connection.getConfig(); const ogLibl = config!.libraryList.slice(0); @@ -190,8 +179,6 @@ describe(`connection tests`, {concurrent: true}, () => { }); test('runCommand (ILE, library list order from variable)', async () => { - const connection = getConnection(); - const result = await connection?.runCommand({ command: `DSPLIBL`, environment: `ile`, @@ -209,9 +196,7 @@ describe(`connection tests`, {concurrent: true}, () => { expect(qtempIndex < qsysincIndex).toBeTruthy(); }); - test('runCommand (ILE, library order from config)', async () => { - const connection = getConnection(); - const config = connection.getConfig(); + test('runCommand (ILE, library order from config)', async () => { const config = connection.getConfig(); const ogLibl = config!.libraryList.slice(0); @@ -233,9 +218,7 @@ describe(`connection tests`, {concurrent: true}, () => { expect(qtempIndex < qsysincIndex).toBeTruthy(); }); - test('withTempDirectory and countFiles', async () => { - const connection = getConnection(); - const content = connection.getContent()!; + test('withTempDirectory and countFiles', async () => { const content = connection.getContent()!; let temp; await connection.withTempDirectory(async tempDir => { @@ -265,8 +248,7 @@ describe(`connection tests`, {concurrent: true}, () => { test('upperCaseName', () => { { - const connection = getConnection(); - const variantsBackup = connection.variantChars.local; + const variantsBackup = connection.variantChars.local; try { //CCSID 297 variants @@ -285,5 +267,24 @@ describe(`connection tests`, {concurrent: true}, () => { connection.variantChars.local = variantsBackup; } } - }) + }); + + it('Check Java versions', async () => { + if (connection.remoteFeatures.jdk80) { + const jdk8 = getJavaHome(connection, '8'); + expect(jdk8).toBe(connection.remoteFeatures.jdk80); + } + + if (connection.remoteFeatures.jdk11) { + const jdk11 = getJavaHome(connection, '11'); + expect(jdk11).toBe(connection.remoteFeatures.jdk11); + } + + if (connection.remoteFeatures.jdk17) { + const jdk17 = getJavaHome(connection, '17'); + expect(jdk17).toBe(connection.remoteFeatures.jdk17); + } + + expect(getJavaHome(connection, '666')).toBeUndefined(); + }); }) \ No newline at end of file diff --git a/src/api/tests/suites/content.test.ts b/src/api/tests/suites/content.test.ts index 8c02bce01..587ab46fd 100644 --- a/src/api/tests/suites/content.test.ts +++ b/src/api/tests/suites/content.test.ts @@ -1,14 +1,23 @@ -import { expect, describe, it } from 'vitest'; -import { getConnection } from '../state'; +import { expect, describe, it, afterAll, beforeAll } from 'vitest'; import util, { TextDecoder } from 'util'; import tmp from 'tmp'; import { Tools } from '../../Tools'; import { posix } from 'path'; +import IBMi from '../../IBMi'; +import { newConnection, disposeConnection } from '../globalSetup'; describe('Content Tests', {concurrent: true}, () => { + let connection: IBMi + beforeAll(async () => { + connection = await newConnection(); + }) + + afterAll(async () => { + disposeConnection(connection); + }); + it('memberResolve', async () => { - const connection = getConnection(); const content = connection.getContent(); const member = await content?.memberResolve('MATH', [ @@ -27,7 +36,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('memberResolve (with invalid ASP)', async () => { - const connection = getConnection(); const content = connection.getContent(); const member = await content?.memberResolve('MATH', [ @@ -46,7 +54,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('memberResolve with variants', async () => { - const connection = getConnection(); const content = connection.getContent(); const config = connection.getConfig(); const tempLib = config!.tempLibrary, @@ -81,7 +88,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('memberResolve with bad name', async () => { - const connection = getConnection(); const content = connection.getContent(); const member = await content?.memberResolve('BOOOP', [ @@ -94,7 +100,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('objectResolve .FILE', async () => { - const connection = getConnection(); const content = connection.getContent(); const lib = await content?.objectResolve('MIH', [ @@ -106,7 +111,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('objectResolve .PGM', async () => { - const connection = getConnection(); const content = connection.getContent(); const lib = await content?.objectResolve('CMRCV', [ @@ -118,7 +122,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('objectResolve .DTAARA with variants', async () => { - const connection = getConnection(); const content = connection.getContent(); const config = connection.getConfig(); const tempLib = config!.tempLibrary, @@ -145,7 +148,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('objectResolve with bad name', async () => { - const connection = getConnection(); const content = connection.getContent(); const lib = await content?.objectResolve('BOOOP', [ @@ -158,7 +160,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('streamfileResolve', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const streamfilePath = await content?.streamfileResolve(['git'], ['/QOpenSys/pkgs/sbin', '/QOpenSys/pkgs/bin']); @@ -166,7 +168,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('streamfileResolve with bad name', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const streamfilePath = await content?.streamfileResolve(['sup'], ['/QOpenSys/pkgs/sbin', '/QOpenSys/pkgs/bin']); @@ -174,7 +176,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('streamfileResolve with multiple names', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const streamfilePath = await content?.streamfileResolve(['sup', 'sup2', 'git'], ['/QOpenSys/pkgs/sbin', '/QOpenSys/pkgs/bin']); @@ -182,7 +184,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('streamfileResolve with blanks in names', async () => { - const connection = getConnection(); const content = connection.getContent(); const files = ['normalname', 'name with blank', 'name_with_quote\'', 'name_with_dollar$']; const dir = `/tmp/${Date.now()}`; @@ -210,7 +211,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test downloadMemberContent', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const tmpFile = await util.promisify(tmp.file)(); const memberContent = await content?.downloadMemberContent(undefined, 'QSYSINC', 'H', 'MATH', tmpFile); @@ -219,7 +220,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test runSQL (basic select)', async () => { - const connection = getConnection(); const rows = await connection.runSQL('select * from qiws.qcustcdt'); expect(rows?.length).not.toBe(0); @@ -230,7 +230,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test runSQL (bad basic select)', async () => { - const connection = getConnection(); try { await connection.runSQL('select from qiws.qcustcdt'); @@ -242,7 +241,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test runSQL (with comments)', async () => { - const connection = getConnection(); const rows = await connection.runSQL([ '-- myselect', @@ -255,7 +253,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test getTable', async () => { - const connection = getConnection(); const content = connection.getContent(); const rows = await content.getTable('qiws', 'qcustcdt', '*all'); @@ -268,7 +265,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test validateLibraryList', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const badLibs = await content.validateLibraryList(['SCOOBY', 'QSYSINC', 'BEEPBOOP']); @@ -278,7 +275,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test getFileList', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const objects = await content?.getFileList('/'); @@ -291,7 +288,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test getFileList (non-existing file)', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const objects = await content?.getFileList(`/tmp/${Date.now()}`); @@ -299,8 +296,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test getFileList (special chars)', async () => { - const connection = getConnection(); - const content = getConnection().getContent(); + const content = connection.getContent(); const files = ['name with blank', 'name_with_quote\'', 'name_with_dollar$']; const dir = `/tmp/${Date.now()}`; const dirWithSubdir = `${dir}/${files[0]}`; @@ -326,7 +322,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test getObjectList (all objects)', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const objects = await content?.getObjectList({ library: 'QSYSINC' }); @@ -334,7 +330,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test getObjectList (pgm filter)', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const objects = await content?.getObjectList({ library: 'QSYSINC', types: ['*PGM'] }); @@ -346,7 +342,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test getObjectList (source files only)', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const objects = await content?.getObjectList({ library: 'QSYSINC', types: ['*SRCPF'] }); @@ -358,7 +354,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test getObjectList (single source file only, detailed)', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const objectsA = await content?.getObjectList({ library: 'QSYSINC', types: ['*SRCPF'], object: 'MIH' }); @@ -366,7 +362,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test getObjectList (source files only, named filter)', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const objects = await content?.getObjectList({ library: 'QSYSINC', types: ['*SRCPF'], object: 'MIH' }); @@ -377,7 +373,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('getLibraries (simple filters)', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const qsysLibraries = await content?.getLibraries({ library: 'QSYS*' }); expect(qsysLibraries?.length).not.toBe(0); @@ -394,7 +390,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('getLibraries (regexp filters)', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const qsysLibraries = await content?.getLibraries({ library: '^.*SYS[^0-9]*$', filterType: 'regex' }); expect(qsysLibraries?.length).not.toBe(0); @@ -402,7 +398,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('getObjectList (advanced filtering)', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const objects = await content?.getObjectList({ library: 'QSYSINC', object: 'L*OU*' }); expect(objects?.length).not.toBe(0); @@ -410,7 +406,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('getMemberList (SQL, no filter)', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); let members = await content?.getMemberList({ library: 'qsysinc', sourceFile: 'mih', members: '*inxen' }); @@ -428,7 +424,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('getMemberList (advanced filtering)', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const members = await content?.getMemberList({ library: 'QSYSINC', sourceFile: 'QRPGLESRC', members: 'SYS*,I*,*EX' }); expect(members?.length).not.toBe(0); @@ -440,7 +436,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('getQtempTable', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const queries = [ `CALL QSYS2.QCMDEXC('DSPOBJD OBJ(QSYSINC/*ALL) OBJTYPE(*ALL) OUTPUT(*OUTFILE) OUTFILE(QTEMP/DSPOBJD)')`, @@ -473,7 +469,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('toCl', () => { - const command = getConnection().getContent().toCl("TEST", { + const command = connection.getContent().toCl("TEST", { ZERO: 0, NONE: '*NONE', EMPTY: `''`, @@ -486,21 +482,21 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Check object (no exist)', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const exists = await content?.checkObject({ library: 'QSYSINC', name: 'BOOOP', type: '*FILE' }); expect(exists).toBe(false); }); it('Check object (source member)', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const exists = await content?.checkObject({ library: 'QSYSINC', name: 'H', type: '*FILE', member: 'MATH' }); expect(exists).toBeTruthy(); }); it('Check getMemberInfo', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const memberInfoA = await content?.getMemberInfo('QSYSINC', 'H', 'MATH'); expect(memberInfoA).toBeTruthy(); @@ -527,7 +523,7 @@ describe('Content Tests', {concurrent: true}, () => { }); it('Test @clCommand + select statement', async () => { - const content = getConnection().getContent(); + const content = connection.getContent(); const [resultA] = await content.runSQL(`@CRTSAVF FILE(QTEMP/UNITTEST) TEXT('Code for i test');\nSelect * From Table(QSYS2.OBJECT_STATISTICS('QTEMP', '*FILE')) Where OBJATTRIBUTE = 'SAVF';`); @@ -544,7 +540,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('should get attributes', async () => { - const connection = getConnection(); const content = connection.getContent() await connection.withTempDirectory(async directory => { expect((await connection.sendCommand({ command: 'echo "I am a test file" > test.txt', directory })).code).toBe(0); @@ -576,7 +571,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('should count members', async () => { - const connection = getConnection(); const content = connection.getContent() const tempLib = connection.config?.tempLibrary; if (tempLib) { @@ -608,7 +602,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('should create streamfile', async () => { - const connection = getConnection(); const content = connection.getContent() await connection.withTempDirectory(async dir => { const file = posix.join(dir, Tools.makeid()); @@ -623,7 +616,6 @@ describe('Content Tests', {concurrent: true}, () => { }); it('should handle long library name', async () => { - const connection = getConnection(); const content = connection.getContent() const longName = Tools.makeid(18); const shortName = Tools.makeid(8); diff --git a/src/api/tests/suites/debug.test.ts b/src/api/tests/suites/debug.test.ts deleted file mode 100644 index 9934de5dc..000000000 --- a/src/api/tests/suites/debug.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { describe, it, expect } from 'vitest'; -import { getConnection } from '../state'; -import { getJavaHome } from '../../configuration/DebugConfiguration'; - -describe('Debug engine tests', () => { - it('Check Java versions', async () => { - const connection = getConnection(); - - if (connection.remoteFeatures.jdk80) { - const jdk8 = getJavaHome(connection, '8'); - expect(jdk8).toBe(connection.remoteFeatures.jdk80); - } - - if (connection.remoteFeatures.jdk11) { - const jdk11 = getJavaHome(connection, '11'); - expect(jdk11).toBe(connection.remoteFeatures.jdk11); - } - - if (connection.remoteFeatures.jdk17) { - const jdk17 = getJavaHome(connection, '17'); - expect(jdk17).toBe(connection.remoteFeatures.jdk17); - } - - expect(getJavaHome(connection, '666')).toBeUndefined(); - }); -}); diff --git a/src/api/tests/suites/encoding.test.ts b/src/api/tests/suites/encoding.test.ts index e20c1df9c..8b8b7745e 100644 --- a/src/api/tests/suites/encoding.test.ts +++ b/src/api/tests/suites/encoding.test.ts @@ -2,8 +2,8 @@ import path from "path"; import IBMi from "../../IBMi"; import { Tools } from "../../Tools"; import { IBMiObject } from "../../types"; -import { describe, it, expect } from 'vitest'; -import { getConnection } from "../state"; +import { describe, it, expect, afterAll, beforeAll } from 'vitest'; +import { newConnection, disposeConnection } from "../globalSetup"; const contents = { '37': [`Hello world`], @@ -39,9 +39,17 @@ async function runCommandsWithCCSID(connection: IBMi, commands: string[], ccsid: return result; } -describe('Encoding tests', () => { - it('Prove that input strings are messed up by CCSID', async () => { - const connection = getConnection(); +describe('Encoding tests', {concurrent: true} ,() => { + let connection: IBMi + beforeAll(async () => { + connection = await newConnection(); + }) + + afterAll(async () => { + disposeConnection(connection); + }); + + it('Prove that input strings are messed up by CCSID', {timeout: 40000}, async () => { let howManyTimesItMessedUpTheResult = 0; for (const strCcsid in contents) { @@ -62,10 +70,9 @@ describe('Encoding tests', () => { } expect(howManyTimesItMessedUpTheResult).toBeTruthy(); - }, {timeout: 40000}); + }); it('Compare Unicode to EBCDIC successfully', async () => { - const connection = getConnection(); const sql = `select table_name, table_owner from qsys2.systables where table_schema = ? and table_name = ?`; const result = await connection?.runSQL(sql, { fakeBindings: [`QSYS2`, `SYSCOLUMNS`] }); @@ -73,7 +80,6 @@ describe('Encoding tests', () => { }); it('Run variants through shells', async () => { - const connection = getConnection(); const text = `Hello${connection?.variantChars.local}world`; const basicCommandA = `echo "${IBMi.escapeForShell(text)}"`; @@ -107,8 +113,6 @@ describe('Encoding tests', () => { }); it('streamfileResolve with dollar', async () => { - const connection = getConnection()!; - await connection.withTempDirectory(async tempDir => { const tempFile = path.posix.join(tempDir, `$hello`); await connection.content.createStreamFile(tempFile); @@ -121,8 +125,6 @@ describe('Encoding tests', () => { SHELL_CHARS.forEach(char => { it(`Test streamfiles with shell character ${char}`, async () => { - const connection = getConnection()!; - const nameCombos = [`${char}ABC`, `ABC${char}`, `${char}ABC${char}`, `A${char}C`]; await connection.withTempDirectory(async tempDir => { @@ -140,7 +142,6 @@ describe('Encoding tests', () => { }); it(`Test members with shell character ${char}`, async () => { - const connection = getConnection(); const content = connection.getContent(); const config = connection.getConfig() @@ -176,8 +177,7 @@ describe('Encoding tests', () => { }); it('Listing objects with variants', async () => { - const connection = getConnection(); - const content = getConnection()?.content; + const content = connection.getContent(); if (connection && content) { const tempLib = connection.config?.tempLibrary!; const ccsid = connection.getCcsid(); @@ -259,7 +259,6 @@ describe('Encoding tests', () => { }); it('Library list supports dollar sign variant', async () => { - const connection = getConnection()!; const library = `TEST${connection.variantChars.local}LIB`; const sourceFile = `TEST${connection.variantChars.local}FIL`; const member = `TEST${connection.variantChars.local}MBR`; @@ -290,7 +289,6 @@ describe('Encoding tests', () => { }); it('Variant character in source names and commands', async () => { - const connection = getConnection(); const config = connection.getConfig(); const ccsidData = connection.getCcsids()!; diff --git a/src/api/tests/suites/search.test.ts b/src/api/tests/suites/search.test.ts index 7dbdc337f..2cd829c0d 100644 --- a/src/api/tests/suites/search.test.ts +++ b/src/api/tests/suites/search.test.ts @@ -1,11 +1,21 @@ -import { describe, it, expect } from 'vitest'; +import { describe, it, expect, afterAll, beforeAll } from 'vitest'; import { parseFilter } from '../../Filter'; import { Search } from '../../Search'; -import { getConnection } from '../state'; +import IBMi from '../../IBMi'; +import { newConnection, disposeConnection } from '../globalSetup'; describe('Search Tests', {concurrent: true}, () => { + let connection: IBMi + beforeAll(async () => { + connection = await newConnection(); + }) + + afterAll(async () => { + disposeConnection(connection); + }); + it('Single member search', async () => { - const result = await Search.searchMembers(getConnection(), "QSYSINC", "QRPGLESRC", "IBM", "CMRPG"); + const result = await Search.searchMembers(connection, "QSYSINC", "QRPGLESRC", "IBM", "CMRPG"); expect(result.term).toBe("IBM"); expect(result.hits.length).toBe(1); const [hit] = result.hits; @@ -24,7 +34,7 @@ describe('Search Tests', {concurrent: true}, () => { it('Generic name search', async () => { const memberFilter = "E*"; const filter = parseFilter(memberFilter); - const result = await Search.searchMembers(getConnection(), "QSYSINC", "QRPGLESRC", "IBM", memberFilter); + const result = await Search.searchMembers(connection, "QSYSINC", "QRPGLESRC", "IBM", memberFilter); expect(result.hits.every(hit => filter.test(hit.path.split("/").at(-1)!))).toBe(true); expect(result.hits.every(hit => !hit.path.endsWith(`MBR`))).toBe(true); }); @@ -36,10 +46,10 @@ describe('Search Tests', {concurrent: true}, () => { const filter = parseFilter(memberFilter); const checkNames = (names: string[]) => names.every(filter.test); - const members = await getConnection().getContent().getMemberList({ library, sourceFile, members: memberFilter }); + const members = await connection.getContent().getMemberList({ library, sourceFile, members: memberFilter }); expect(checkNames(members.map(member => member.name))).toBe(true); - const result = await Search.searchMembers(getConnection(), "QSYSINC", "QRPGLESRC", "SQL", members); + const result = await Search.searchMembers(connection, "QSYSINC", "QRPGLESRC", "SQL", members); expect(result.hits.length).toBe(6); expect(checkNames(result.hits.map(hit => hit.path.split("/").at(-1)!))).toBe(true); expect(result.hits.every(hit => !hit.path.endsWith(`MBR`))).toBe(true); diff --git a/vitest.config.ts b/vitest.config.ts index fe0530057..ff1871fb8 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -6,9 +6,6 @@ export default defineConfig({ // ... Specify options here. fileParallelism: false, root: './src/api', - setupFiles: [ - 'tests/globalSetup.ts', - ], testTimeout: 10000 }, }) \ No newline at end of file