Skip to content

Commit

Permalink
test: use correct test package name
Browse files Browse the repository at this point in the history
  • Loading branch information
anantoghosh committed Feb 25, 2021
1 parent 54da07f commit fa0d212
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions scripts/test.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
// @ts-check
const execa = require('execa');
const stdio = 'inherit';
const fs = require('fs');

/** Commands */
const pack = 'npm pack';
const installDeps =
'npm i -D eslint typescript @typescript-eslint/eslint-plugin eslint-plugin-sonarjs eslint-plugin-unicorn';
const installPackage = (packageName) => `npm i -D ../${packageName[0]}`;
const runTest = 'npm run test';


/** Outputs to stdio */
function sh(command) {
return execa.command(command, {
stdio,
});
}

/** Main */
(async () => {
try {
console.log('Packing');
await execa('npm', ['pack'], {
stdio,
console.log('🚀 Packing');
await sh(pack);

const files = fs.readdirSync('.', 'utf8');
const packageName = files.filter((file) => {
return file.includes('eslint-config-good-code-');
});

console.log('Changing to test directory');
console.log('🚀 Changing to test directory');
process.chdir('test');

console.log('Installing required dependencies');
await execa.command(
'npm i -D eslint typescript @typescript-eslint/eslint-plugin eslint-plugin-sonarjs eslint-plugin-unicorn',
{
stdio,
}
);

console.log('Installing this package locally');
await execa.command('npm i -D ../eslint-config-good-code-1.0.2.tgz --force', {
stdio,
});
console.log('🚀 Installing required dependencies');
await sh(installDeps);

console.log('Running eslint test');
await execa.command('npm run test', {
stdio,
});
console.log('🚀 Installing this package locally:', packageName[0]);
await sh(installPackage(packageName));

console.log('🚀 Running eslint test');
await sh(runTest);

const result = require('../test/1.json');

if (result[0]['errorCount'] !== 7) {
throw new Error('Eslint error count mismatch');
}

console.log("Test passed ✅");
console.log('🚀 Test passed ✅');
} catch (error) {
console.error(error);
}
Expand Down

0 comments on commit fa0d212

Please sign in to comment.