@amiceli/vitest-cucumber
Version:
vitest tools to use Gherkin feature in unit tests
36 lines (35 loc) • 1.45 kB
JavaScript
import fs from 'node:fs';
import path from 'node:path';
import { FeatureAst } from './ast/FeatureAst';
export function VitestCucumberPlugin(options) {
return {
name: 'vitest-cucumber-plugin',
configureServer(server) {
const featureDir = path.resolve(process.cwd(), options.featureFilesDir);
fs.watch(featureDir, { recursive: true }, async (_, filename) => {
if (filename?.endsWith('.feature')) {
const featureFilePath = `${options.featureFilesDir}${filename}`;
const specFilePath = featureFilePath.replace('.feature', '.spec.ts');
try {
if (fs.existsSync(specFilePath) === false) {
fs.writeFileSync(specFilePath, '');
}
await FeatureAst.fromOptions({
featureFilePath,
specFilePath,
onDeleteAction: options.onDeleteAction,
formatCommand: options.formatCommand,
}).updateSpecFile();
}
catch (e) {
console.error(e);
}
server.ws.send({
type: 'full-reload',
path: '*',
});
}
});
},
};
}