From e7dfd1dc503014f59bd1d1fccedad2bc9c4e9faf Mon Sep 17 00:00:00 2001 From: Christopher Goddard Date: Fri, 19 Nov 2021 09:24:26 +1100 Subject: [PATCH 1/2] Use fsPromises --- packages/zcli-apps/tests/functional/server.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/zcli-apps/tests/functional/server.test.ts b/packages/zcli-apps/tests/functional/server.test.ts index 06cde11c..820e41ee 100644 --- a/packages/zcli-apps/tests/functional/server.test.ts +++ b/packages/zcli-apps/tests/functional/server.test.ts @@ -2,6 +2,7 @@ import { expect, test } from '@oclif/test' import * as path from 'path' import * as http from 'http' import fetch from 'node-fetch' +import { promises as fsPromise } from 'fs' import * as fs from 'fs' import { omit } from 'lodash' import ServerCommand from '../../src/commands/apps/server' @@ -105,16 +106,15 @@ describe('apps server', function () { const manifest: Manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) const appName = manifest.name manifest.name = `${appName} modified` - // Modifed manifest.json - fs.writeFileSync(manifestPath, JSON.stringify(manifest)) - await wait() + // Modify manifest.json + await fsPromise.writeFile(manifestPath, JSON.stringify(manifest)) const response = await fetch(`${appHost}/app.json`) appsJSON = await response.json() const appJSON = appsJSON.apps[index] expect(appJSON.name).to.eq(`${appName} modified`) - // Restored manifest.json + // Restore manifest.json manifest.name = appName - fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2)) + await fsPromise.writeFile(manifestPath, JSON.stringify(manifest, null, 2)) })) }) }) From 1adec5ee06dc1551dc373323d84a490cb2314eff Mon Sep 17 00:00:00 2001 From: Christopher Goddard Date: Fri, 19 Nov 2021 09:27:52 +1100 Subject: [PATCH 2/2] Add comment indicating how to proceed --- packages/zcli-apps/tests/functional/server.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/zcli-apps/tests/functional/server.test.ts b/packages/zcli-apps/tests/functional/server.test.ts index 820e41ee..eb08b7d8 100644 --- a/packages/zcli-apps/tests/functional/server.test.ts +++ b/packages/zcli-apps/tests/functional/server.test.ts @@ -108,6 +108,8 @@ describe('apps server', function () { manifest.name = `${appName} modified` // Modify manifest.json await fsPromise.writeFile(manifestPath, JSON.stringify(manifest)) + // Wait for setAppAssetsMiddleware() spy to be called to ensure that change has been written + // TODO implement spy on said method here and/or however this works in Cypress / Puppeteer perhaps on the route const response = await fetch(`${appHost}/app.json`) appsJSON = await response.json() const appJSON = appsJSON.apps[index]