add a test for the example

Signed-off-by: Brian Fletcher <brian@roadie.io>
This commit is contained in:
Brian Fletcher
2022-12-20 16:30:17 +00:00
parent b44eb68bcb
commit 81c94a919f
2 changed files with 56 additions and 1 deletions
@@ -20,6 +20,7 @@ import os from 'os';
import { Writable } from 'stream';
import { createDebugLogAction } from './log';
import { join } from 'path';
import yaml from 'yaml';
describe('debug:log', () => {
const logStream = {
@@ -91,4 +92,43 @@ describe('debug:log', () => {
expect.stringContaining('Hello Backstage!'),
);
});
it('should log the workspace content from an example, if active', async () => {
const example = action.examples?.find(
sample => sample.description === 'List the workspace directory',
)?.example as string;
expect(typeof example).toEqual('string');
const context = {
...mockContext,
...yaml.parse(example).steps[0],
};
await action.handler(context);
expect(logStream.write).toHaveBeenCalledTimes(1);
expect(logStream.write).toHaveBeenCalledWith(
expect.stringContaining('README.md'),
);
expect(logStream.write).toHaveBeenCalledWith(
expect.stringContaining(join('a-directory', 'index.md')),
);
});
it('should log message from an example', async () => {
const example = action.examples?.find(
sample => sample.description === 'Write a debug message',
)?.example as string;
const context = {
...mockContext,
...yaml.parse(example).steps[0],
};
await action.handler(context);
expect(logStream.write).toHaveBeenCalledTimes(1);
expect(logStream.write).toHaveBeenCalledWith(
expect.stringContaining('Hello Backstage!'),
);
});
});
@@ -31,7 +31,22 @@ const examples = [
id: 'write-debug-line',
name: 'Write log line',
input: {
message: 'Hello, there',
message: 'Hello Backstage!',
},
},
],
}),
},
{
description: 'List the workspace directory',
example: yaml.stringify({
steps: [
{
action: id,
id: 'write-debug-line',
name: 'Write log line',
input: {
listWorkspace: true,
},
},
],