Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/commands/dump.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
exports.name = 'dump';
exports.command = {
help: `serializes and saves an object as .json (args: space separated file and the object to dump)`,
action(file_objVar) {
const [file, objVar] = file_objVar.split(/\s+/);
if (!file || !objVar) return;
const line = `await fs.promises.writeFile("${file}.json", JSON.stringify(${objVar}, null, ' '));`;
this.eval(line, this.context, '', () => {
this.lines.push(line);
});
this.displayPrompt();
},
};
35 changes: 35 additions & 0 deletions lib/commands/dump.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const test = require('ava');
const dump = require('./dump');
const Scriptwriter = require('../scriptwriter');

test.serial('uses the correct interface', (t) => {
t.truthy(dump.name);
t.truthy(dump.command.help);
t.truthy(dump.command.action);
});

test.serial('action', (t) => {
const scriptwriter = new Scriptwriter();
let displayPromptCalled = false;
const mockReplServer = {
context: {
scriptwriter,
},
displayPrompt() {
displayPromptCalled = true;
},
lines: [],
eval(line, context, file, cb) {
cb();
},
};
dump.command.action.call(mockReplServer, 'myobj {a:1}');
t.true(displayPromptCalled);
t.deepEqual(
mockReplServer.lines,
[
`await fs.promises.writeFile("myobj.json", JSON.stringify({a:1}, null, ' '));`,
],
'prints the correct command in .save history'
);
});
10 changes: 2 additions & 8 deletions lib/scriptwriter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,8 @@ test.serial('completer ', async (t) => {
'can handle the last token'
);
t.deepEqual(
scriptwriter.completer('await page.accessibility.'),
[
[
'await page.accessibility._getAXTree',
'await page.accessibility.snapshot',
],
'await page.accessibility.',
],
scriptwriter.completer('await page.accessibility.s'),
[['await page.accessibility.snapshot'], 'await page.accessibility.s'],
'can handle nested and within a line of syntax'
);
t.deepEqual(
Expand Down
Loading