webpack-auto-inject-version/demo/tests/test.spec.js

170 lines
4.7 KiB
JavaScript
Raw Normal View History

import webpackCompile from './helpers/webpack-compile';
import getDistFile from './helpers/get-dist-file';
import testWebpackConfigs from './webpack-configs';
import cheerio from 'cheerio';
describe('Inject by tag', () => {
// default inject by tag tests
describe('default', () => {
const config = {
SILENT: true,
2018-10-28 04:59:02 +11:00
components: {
AutoIncreaseVersion: false,
InjectAsComment: false,
InjectByTag: true,
},
componentsOptions: {
InjectByTag: {
dateFormat: '_HH:mm:ss_',
},
},
};
// container for webpack iterations
describe('Iterate webpack configs', async () => {
for (const [webpackConfName, webpackConfig] of testWebpackConfigs) {
describe(`webpack: ${webpackConfName}`, () => {
it('prepare', async () => {
await webpackCompile(webpackConfig, config);
});
it('Should not include any not parsed tags', async () => {
const distMainJS = getDistFile('js/main.js');
expect(distMainJS).to.not.include('[AIV]');
expect(distMainJS).to.not.include('[/AIV]');
});
it('Should properly parse date', () => {
const distMainJS = getDistFile('js/main.js');
const $ = cheerio.load(distMainJS);
const date = $('#date').text().trim();
expect(/^(_\d\d:\d\d:\d\d_)$/.test(date)).to.be.true;
});
2018-10-28 04:59:02 +11:00
});
}
});
});
});
describe('Inject as comment', () => {
// default inject by tag tests
describe('default', () => {
const config = {
SILENT: true,
components: {
AutoIncreaseVersion: false,
InjectAsComment: true,
InjectByTag: false,
},
componentsOptions: {
InjectAsComment: {
tag: '_Version: {version} - {date}',
dateFormat: '_HH:mm:ss_',
// multiLineCommentType: true
},
},
};
// container for webpack iterations
describe('Iterate webpack configs', async () => {
for (const [webpackConfName, webpackConfig] of testWebpackConfigs) {
describe(`webpack: ${webpackConfName}`, () => {
it('prepare', async () => {
await webpackCompile(webpackConfig, config);
});
2018-10-28 04:59:02 +11:00
it('Should include AIV_SHORT comment block', async () => {
const distMainJS = getDistFile('js/main.js');
expect(distMainJS).to.include('[AIV_SHORT] _Version:');
});
2018-10-28 04:59:02 +11:00
it('Should use single line comment block', () => {
const distMainJS = getDistFile('js/main.js');
expect(distMainJS).to.match(/^(\/\/)/);
});
});
}
});
});
2018-10-28 04:59:02 +11:00
// default inject by tag tests
describe('multiline', () => {
const config = {
SILENT: true,
components: {
AutoIncreaseVersion: false,
InjectAsComment: true,
InjectByTag: false,
},
componentsOptions: {
InjectAsComment: {
tag: '_Version: {version} - {date}',
dateFormat: '_HH:mm:ss_',
multiLineCommentType: true
},
},
};
2018-10-28 04:59:02 +11:00
// container for webpack iterations
describe('Iterate webpack configs', async () => {
for (const [webpackConfName, webpackConfig] of testWebpackConfigs) {
describe(`webpack: ${webpackConfName}`, () => {
it('prepare', async () => {
await webpackCompile(webpackConfig, config);
});
it('Should use multiline comment block', () => {
const distMainJS = getDistFile('js/main.js');
expect(distMainJS).to.match(/^(\/\*\*)/);
});
});
}
});
});
});
2018-10-28 04:59:02 +11:00
describe('Auto increase version', () => {
// default inject by tag tests
describe('default', () => {
const config = {
SILENT: true,
components: {
AutoIncreaseVersion: true,
InjectAsComment: true,
InjectByTag: false,
},
componentsOptions: {
AutoIncreaseVersion: {
runInWatchMode: true,
simulate: true, // testing purpose only
forceMode: 'patch', // testing purpose only
},
},
};
// container for webpack iterations
describe('Iterate webpack configs', async () => {
for (const [webpackConfName, webpackConfig] of testWebpackConfigs) {
describe(`webpack: ${webpackConfName}`, () => {
it('prepare', async () => {
await webpackCompile(webpackConfig, config);
});
it('InjectAsComment should include correct AIV version', async () => {
const distMainJS = getDistFile('js/main.js');
expect(distMainJS).to.include('0.14.1');
});
});
}
});
});
});