|
| 1 | +import * as assert from 'assert' |
| 2 | +import { IntegrationBundleServerWorld } from '../support/world' |
| 3 | +import { Given, Then } from '@cucumber/cucumber' |
| 4 | +import * as utils from '../../../shared/support/utils' |
| 5 | +import * as fs from 'fs' |
| 6 | + |
| 7 | +Given('a bundle server repository is created at route {string} for the remote', async function (this: IntegrationBundleServerWorld, route: string) { |
| 8 | + if (!this.remote) { |
| 9 | + throw new Error("Remote has not been initialized") |
| 10 | + } |
| 11 | + this.bundleServer.init(this.remote, 'integration', route) |
| 12 | +}) |
| 13 | + |
| 14 | +Given('no bundle server repository exists at route {string}', async function (this: IntegrationBundleServerWorld, route: string) { |
| 15 | + var repoPath = utils.repoRoot(route) |
| 16 | + if (fs.existsSync(repoPath)) { |
| 17 | + throw new Error(`Repo already exists at ${repoPath}`) |
| 18 | + } |
| 19 | +}) |
| 20 | + |
| 21 | +Then('a bundle server repository exists at route {string}', async function (this: IntegrationBundleServerWorld, route: string) { |
| 22 | + var repoRoot = utils.repoRoot(route) |
| 23 | + assert.equal(fs.existsSync(repoRoot), true) |
| 24 | + assert.equal(fs.existsSync(`${repoRoot}/.git`), false) |
| 25 | + assert.equal(fs.existsSync(`${repoRoot}/HEAD`), true) |
| 26 | + assert.equal(fs.existsSync(`${repoRoot}/bundle-list.json`), true) |
| 27 | + |
| 28 | + // Set route for cleanup |
| 29 | + this.bundleServer.route = route |
| 30 | +}) |
| 31 | + |
| 32 | +Then('the route configuration and repository data at {string} are removed', async function (this: IntegrationBundleServerWorld, route: string) { |
| 33 | + var repoRoot = utils.repoRoot(route) |
| 34 | + var routeData = fs.readFileSync(utils.routesPath()) |
| 35 | + |
| 36 | + assert.equal(fs.existsSync(repoRoot), false) |
| 37 | + assert.equal(routeData.includes(route), false) |
| 38 | + |
| 39 | + // Reset route to be ignored in cleanup |
| 40 | + this.bundleServer.route = undefined |
| 41 | +}) |
| 42 | + |
| 43 | +Then('the bundles are fetched and the bundle list is updated', async function (this: IntegrationBundleServerWorld) { |
| 44 | + assert.strictEqual(this.commandResult?.stdout.toString() |
| 45 | + .includes('Updating bundle list\n' + |
| 46 | + 'Writing updated bundle list\n' + |
| 47 | + 'Update complete'), true) |
| 48 | + |
| 49 | + if (this.bundleServer.initialBundleCount) { |
| 50 | + const currentBundleCount = this.bundleServer.getBundleCount() |
| 51 | + assert.strictEqual(currentBundleCount > this.bundleServer.initialBundleCount, true) |
| 52 | + } else { |
| 53 | + throw new Error("Bundle server not initialized") |
| 54 | + } |
| 55 | +}) |
| 56 | + |
| 57 | +Then('the route is removed from the routes file', async function (this: IntegrationBundleServerWorld) { |
| 58 | + if (this.bundleServer.route) { |
| 59 | + var routesPath = utils.routesPath() |
| 60 | + var data = fs.readFileSync(routesPath); |
| 61 | + assert.strictEqual(data.includes(this.bundleServer.route), false) |
| 62 | + } |
| 63 | +}) |
| 64 | + |
| 65 | +Then('the route exists in the routes file', async function (this: IntegrationBundleServerWorld) { |
| 66 | + if (this.bundleServer.route) { |
| 67 | + var routesPath = utils.routesPath() |
| 68 | + var data = fs.readFileSync(routesPath); |
| 69 | + assert.strictEqual(data.includes(this.bundleServer.route), true) |
| 70 | + } else { |
| 71 | + throw new Error("Route not set") |
| 72 | + } |
| 73 | +}) |
0 commit comments