]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/plugins.ts
Add runner server tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / plugins.ts
index 8aa34fb15e4c4794304ed32d11c0b7d471afd2f4..199d205c79e86cf0ac3fb2197cd2866b44239a0e 100644 (file)
@@ -1,23 +1,24 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
-import * as chai from 'chai'
-import { testHelloWorldRegisteredSettings } from '@server/tests/shared'
+import { expect } from 'chai'
+import { pathExists, remove } from 'fs-extra'
+import { join } from 'path'
+import { SQLCommand, testHelloWorldRegisteredSettings } from '@server/tests/shared'
 import { wait } from '@shared/core-utils'
 import { HttpStatusCode, PluginType } from '@shared/models'
 import {
   cleanupTests,
   createSingleServer,
   killallServers,
+  makeGetRequest,
   PeerTubeServer,
   PluginsCommand,
   setAccessTokensToServers
 } from '@shared/server-commands'
 
-const expect = chai.expect
-
 describe('Test plugins', function () {
-  let server: PeerTubeServer = null
+  let server: PeerTubeServer
+  let sqlCommand: SQLCommand
   let command: PluginsCommand
 
   before(async function () {
@@ -32,6 +33,8 @@ describe('Test plugins', function () {
     await setAccessTokensToServers([ server ])
 
     command = server.plugins
+
+    sqlCommand = new SQLCommand(server)
   })
 
   it('Should list and search available plugins and themes', async function () {
@@ -236,7 +239,7 @@ describe('Test plugins', function () {
 
     async function testUpdate (type: 'plugin' | 'theme', name: string) {
       // Fake update our plugin version
-      await server.sql.setPluginVersion(name, '0.0.1')
+      await sqlCommand.setPluginVersion(name, '0.0.1')
 
       // Fake update package.json
       const packageJSON = await command.getPackageJSON(`peertube-${type}-${name}`)
@@ -349,7 +352,60 @@ describe('Test plugins', function () {
     await check()
   })
 
+  it('Should rebuild native modules on Node ABI change', async function () {
+    this.timeout(60000)
+
+    const removeNativeModule = async () => {
+      await remove(join(baseNativeModule, 'build'))
+      await remove(join(baseNativeModule, 'prebuilds'))
+    }
+
+    await command.install({ path: PluginsCommand.getPluginTestPath('-native') })
+
+    await makeGetRequest({
+      url: server.url,
+      path: '/plugins/test-native/router',
+      expectedStatus: HttpStatusCode.NO_CONTENT_204
+    })
+
+    const query = `UPDATE "application" SET "nodeABIVersion" = 1`
+    await sqlCommand.updateQuery(query)
+
+    const baseNativeModule = server.servers.buildDirectory(join('plugins', 'node_modules', 'a-native-example'))
+
+    await removeNativeModule()
+    await server.kill()
+    await server.run()
+
+    await wait(3000)
+
+    expect(await pathExists(join(baseNativeModule, 'build'))).to.be.true
+    expect(await pathExists(join(baseNativeModule, 'prebuilds'))).to.be.true
+
+    await makeGetRequest({
+      url: server.url,
+      path: '/plugins/test-native/router',
+      expectedStatus: HttpStatusCode.NO_CONTENT_204
+    })
+
+    await removeNativeModule()
+
+    await server.kill()
+    await server.run()
+
+    expect(await pathExists(join(baseNativeModule, 'build'))).to.be.false
+    expect(await pathExists(join(baseNativeModule, 'prebuilds'))).to.be.false
+
+    await makeGetRequest({
+      url: server.url,
+      path: '/plugins/test-native/router',
+      expectedStatus: HttpStatusCode.NOT_FOUND_404
+    })
+  })
+
   after(async function () {
+    await sqlCommand.cleanup()
+
     await cleanupTests([ server ])
   })
 })