From ee4e668f0df5b25f076917eb5ebc46424a564f08 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 16 May 2023 12:43:10 +0200 Subject: [PATCH] config-loader: avoid setTimeout in file watching tests Signed-off-by: Patrik Oldsberg --- .../src/sources/FileConfigSource.test.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/config-loader/src/sources/FileConfigSource.test.ts b/packages/config-loader/src/sources/FileConfigSource.test.ts index c6980006c0..6479fb77c0 100644 --- a/packages/config-loader/src/sources/FileConfigSource.test.ts +++ b/packages/config-loader/src/sources/FileConfigSource.test.ts @@ -64,9 +64,10 @@ describe('FileConfigSource', () => { const source = FileConfigSource.create({ path: tmp.resolve('a.yaml') }); - setTimeout(() => { - tmp.write('a.yaml', 'a: 2'); - }, 10); + source + .readConfigData() + .next() + .then(() => tmp.write('a.yaml', 'a: 2')); await expect(readN(source, 2)).resolves.toEqual([ [{ data: { a: 1 }, context: 'a.yaml', path: tmp.resolve('a.yaml') }], @@ -130,9 +131,10 @@ describe('FileConfigSource', () => { substitutionFunc: async name => (name === 'MY_VALUE' ? '6' : '7'), }); - setTimeout(() => { - tmp.write('x.yaml', '${MY_OTHER_VALUE}'); - }, 10); + source + .readConfigData() + .next() + .then(() => tmp.write('x.yaml', '${MY_OTHER_VALUE}')); await expect(readN(source, 2)).resolves.toEqual([ [{ data: { a: '6' }, context: 'a.yaml', path: tmp.resolve('a.yaml') }], @@ -150,9 +152,10 @@ describe('FileConfigSource', () => { path: tmp.resolve('a.yaml'), }); - setTimeout(() => { - tmp.write('x.txt', '9'); - }, 10); + source + .readConfigData() + .next() + .then(() => tmp.write('x.txt', '9')); await expect(readN(source, 2)).resolves.toEqual([ [{ data: { a: '8' }, context: 'a.yaml', path: tmp.resolve('a.yaml') }],