Skip to content
Open
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
11 changes: 3 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ class TaskKitTask {
return results;
}

// tasks should override process to do any work:
process(input, output, options) {
if (!options) {
options = {};
}
return;
}

Expand All @@ -112,17 +110,14 @@ class TaskKitTask {
const chunks = [];
contents.on('error', (err) => {
this.log(['error'], err);
this.emit('end');
reject(err);
});
contents.on('data', (data) => { chunks.push(data); });
contents.on('close', () => resolve(Buffer.concat(chunks).toString()));
});
const output = path.join(this.options.dist || '', filename);
const outputDir = path.dirname(output);

if (!outputDir) {
return;
}
// mkdirp will create any output directory if it doesn't exist:
await mkdirp(outputDir);
await this.writeFile(output, contents);
let numericSize;
Expand Down
65 changes: 64 additions & 1 deletion test/test.runkit-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ test('execute -- will not fire if no items / files passed', async(t) => {
t.pass();
});

test('execute -- will warn if no items / files passed', async(t) => {
const task = new TaskKitTask('test', {
}, {});
task.process = () => {
t.fail();
};
task.log = (tags, input) => {
t.equal(tags[0], 'warning');
t.equal(input, 'No input files, skipping');
t.end();
};
try {
await task.execute();
} catch (e) {
// do nothing
}
});

test('execute -- can be disabled', async(t) => {
class DisabledTask extends TaskKitTask {
process() {
Expand Down Expand Up @@ -174,6 +192,24 @@ test('writes when contents is stream', async(t) => {
t.end();
});

test('logs and throw error if there is a stream error', async(t) => {
const task = new TaskKitTask('test', {
dist: 'test/dist',
items: {
}
}, {});
task.log = (tags) => {
t.equal(tags[0], 'error');
};
try {
await task.write('stream.txt', fs.createReadStream(`${__dirname}/fixtures/doesNotExist.txt`));
t.fail();
} catch (e) {
t.notEqual(e.toString().indexOf('no such file or directory'), -1);
t.end();
}
});

test('will warn if sizeThreshold is specified and is exceeded ', async(t) => {
const oldLog = console.log;
const results = [];
Expand Down Expand Up @@ -280,5 +316,32 @@ test('writeMany files to dist directory ', async(t) => {
t.equal(data2.toString(), 'contents2');
});

test('can override logger');
test('use the taskkit logger if provided', (t) => {
const task = new TaskKitTask('test', {
dist: 'test/dist',
}, {
logger: (input) => {
t.end();
}
});
task.log();
});

test('warns if write called with empty content', async(t) => {
// t.plan(2);
const task = new TaskKitTask('test', {
dist: 'test/dist',
}, {
logger: (tags, input) => {
t.equal(tags[0], 'warning');
t.equal(input.startsWith('attempting to write empty string to file'), true);
}
});
try {
await task.write('file', undefined);
} catch (e) {
t.end();
}
});

test('can pass in full config');