Files
maven-settings-action/index.test.js
Slawomir Jaranowski 67c2286c8f init commit
2019-10-01 22:14:15 +02:00

43 lines
1.0 KiB
JavaScript

const process = require('process');
const cp = require('child_process');
const path = require('path');
const fs = require('fs');
const testHomePath = path.join(__dirname, 'temp');
const settingsPath = path.join(testHomePath, '.m2', 'settings.xml');
const indexPath = path.join(__dirname, 'index.js');
beforeAll(() => {
if (!fs.existsSync(testHomePath)) {
fs.mkdirSync(testHomePath);
}
process.env['HOME'] = testHomePath;
});
afterEach(() => {
try {
fs.unlinkSync(settingsPath);
} catch (error) {
console.error(error.message);
}
});
afterAll(() => {
try {
fs.rmdirSync(path.join(testHomePath, ".m2"));
fs.rmdirSync(testHomePath);
} catch (error) {
console.error(error.message);
}
});
test('run with default values', () => {
console.log(cp.execSync(`node ${indexPath}`, { env: process.env }).toString());
const settingsStatus = fs.lstatSync(settingsPath);
expect(settingsStatus.isFile()).toBeTruthy();
expect(settingsStatus.size).toBeGreaterThan(0);
})