Skip to content

Commit

Permalink
Slightly refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eilvelia committed May 8, 2024
1 parent f24e55d commit 39625e6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
tar xzvf $_.FullName --directory=$td
}
rm $td/package/package.json
$env:USE_PREBUILT="$td/package/index.js"
$env:PREBUILT_PATH="$td/package/index.js"
npm run integration-tests
if ($LastExitCode -ne 0) {
exit $LastExitCode
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/prebuilt-tdlib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ jobs:
- [ubuntu-latest, tdlib-linux-x64, libtdjson.so]
- [macos-latest, tdlib-macos, libtdjson.dylib]
- [windows-2019, tdlib-windows-x64, tdjson.dll]
env:
LIBTDJSON_PATH: ${{ matrix.os[2] }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -220,6 +218,8 @@ jobs:
with:
name: ${{ matrix.os[1] }}
- run: npm run integration-tests
env:
LIBTDJSON_PATH: ${{ matrix.os[2] }}

publish:
name: 'Publish to npm'
Expand All @@ -229,8 +229,6 @@ jobs:
permissions:
contents: read
id-token: write
env:
TEST_PREBUILT: 1
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -245,6 +243,8 @@ jobs:
path: packages/prebuilt-tdlib/prebuilds/
- run: tree packages/prebuilt-tdlib
- run: npm run integration-tests
env:
PREBUILT_PATH: packages/prebuilt-tdlib
- run: |
git clone https://github.com/tdlib/td td
cd td
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-tdl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Run tests
run: npm run test:all
env:
USE_PREBUILT: package/index.js
PREBUILT_PATH: package/index.js
- uses: actions/upload-artifact@v3
with:
name: tdl-prebuilds
Expand Down
39 changes: 20 additions & 19 deletions packages/tdl/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,28 @@ function createAnyClient (opts: ClientOptions, bare = false): Client {
const managingOpts = {
bare,
receiveTimeout: cfg.receiveTimeout,
executeFunc: execute
executeFunc: execute,
useOldTdjsonInterface: false
}
if (!cfg.useOldTdjsonInterface) {
if (!tdnInitialized) {
tdjsonAddon.tdnew.init(cfg.receiveTimeout)
tdnInitialized = true
}
const tdnManaging = { ...managingOpts, useOldTdjsonInterface: false }
const client = new Client(tdjsonAddon, tdnManaging, opts)
const clientId = client.getClientId()
clientMap.set(clientId, client)
client.once('close', () => {
debug(`Deleting client_id ${clientId}`)
clientMap.delete(clientId)
})
if (!runningReceiveLoop)
receiveLoop()
return client
if (cfg.useOldTdjsonInterface) {
const tdoManaging = { ...managingOpts, useOldTdjsonInterface: true }
return new Client(tdjsonAddon, tdoManaging, opts)
}
if (!tdnInitialized) {
tdjsonAddon.tdnew.init(cfg.receiveTimeout)
tdnInitialized = true
}
const tdoManaging = { ...managingOpts, useOldTdjsonInterface: true }
return new Client(tdjsonAddon, tdoManaging, opts)
const tdnManaging = { ...managingOpts, useOldTdjsonInterface: false }
const client = new Client(tdjsonAddon, tdnManaging, opts)
const clientId = client.getClientId()
clientMap.set(clientId, client)
client.once('close', () => {
debug(`Deleting client_id ${clientId}`)
clientMap.delete(clientId)
})
if (!runningReceiveLoop)
receiveLoop()
return client
}

export function createClient (opts: ClientOptions): Client {
Expand Down
24 changes: 10 additions & 14 deletions tests/integration/tdlib.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,31 @@ const tdl = require('../../packages/tdl')

const projectRoot = path.join(__dirname, '..', '..')

let tdjson
let libdir

if (process.env.TEST_PREBUILT === '1') {
console.log('Using local prebuilt-tdlib')
tdjson = require('../../packages/prebuilt-tdlib').getTdjson()
} else if (process.env.USE_PREBUILT) {
const prebuiltPath = process.env.USE_PREBUILT
console.log(`Using prebuilt-tdlib from '${prebuiltPath}'`)
let tdjson = null

if (process.env.PREBUILT_PATH) {
const prebuiltPath = process.env.PREBUILT_PATH
console.log(`Testing prebuilt-tdlib from '${prebuiltPath}'`)
// $FlowIgnore[unsupported-syntax]
tdjson = require(path.join(projectRoot, prebuiltPath)).getTdjson()
} else if (process.env.LIBTDJSON_PATH) {
const tdjsonPath = process.env.LIBTDJSON_PATH
console.log(`Using tdjson from ${tdjsonPath}`)
console.log(`Testing tdjson from ${tdjsonPath}`)
tdjson = path.isAbsolute(tdjsonPath) ? tdjsonPath : path.join(projectRoot, tdjsonPath)
} else {
libdir = projectRoot
console.log('Testing tdjson from the project root')
tdl.configure({ libdir: projectRoot })
}

if (tdjson) tdl.configure({ tdjson })

let testName = 'tdl'

if (process.env.TEST_OLD_TDJSON === '1') {
testName += ' with useOldTdjsonInterface'
tdl.configure({ useOldTdjsonInterface: true })
}

if (libdir) tdl.configure({ libdir })
else tdl.configure({ tdjson })

describe(testName, () => {
const client = tdl.createBareClient()
const updates = []
Expand Down

0 comments on commit 39625e6

Please sign in to comment.