Skip to content

Commit

Permalink
feat(gscan): use dynamic major version for gscan checks
Browse files Browse the repository at this point in the history
  • Loading branch information
acburdine committed Oct 16, 2019
1 parent 312c478 commit e74d1fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
8 changes: 5 additions & 3 deletions lib/tasks/major-update/data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

module.exports = async function getData({dir, database, versionFolder}) {
module.exports = async function getData({dir, database, versionFolder, version}) {
const path = require('path');
const semver = require('semver');
const {CliError} = require('../../errors');

if (!dir) {
Expand Down Expand Up @@ -39,10 +40,11 @@ module.exports = async function getData({dir, database, versionFolder}) {
themeFolder = path.resolve(dir, versionFolder, 'content', 'themes');
}

const report = await gscan.check(path.resolve(themeFolder, activeTheme));
const checkVersion = `v${semver.major(version)}`;
const report = await gscan.check(path.resolve(themeFolder, activeTheme), {checkVersion});

return {
gscanReport: gscan.format(report, {sortByFiles: true}),
gscanReport: gscan.format(report, {sortByFiles: true, checkVersion}),
demoPost: await query('SELECT uuid FROM posts WHERE `slug` = "v2-demo-post";')
};
} finally {
Expand Down
25 changes: 21 additions & 4 deletions test/unit/tasks/major-update/data-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ describe('Unit: Tasks > Major Update > Data', function () {

data = proxyquire('../../../../lib/tasks/major-update/data', {
'/var/www/ghost/versions/2.0.0/node_modules/knex': knexMock,
'/var/www/ghost/versions/2.0.0/node_modules/gscan': gscanMock
'/var/www/ghost/versions/2.0.0/node_modules/gscan': gscanMock,
'/var/www/ghost/versions/3.0.0/node_modules/knex': knexMock,
'/var/www/ghost/versions/3.0.0/node_modules/gscan': gscanMock
});
});

Expand Down Expand Up @@ -61,7 +63,8 @@ describe('Unit: Tasks > Major Update > Data', function () {
client: 'sqlite3'
},
dir: '/var/www/ghost/',
versionFolder: 'versions/2.0.0/'
versionFolder: 'versions/2.0.0/',
version: '2.0.0'
});

expect(response.gscanReport.formatted).to.be.true;
Expand All @@ -71,6 +74,10 @@ describe('Unit: Tasks > Major Update > Data', function () {
expect(connection.raw.calledTwice).to.be.true;

expect(gscanMock.check.calledOnce).to.be.true;
expect(gscanMock.check.calledWithExactly(
'/var/www/ghost/versions/2.0.0/content/themes/casper',
{checkVersion: 'v2'}
)).to.be.true;
expect(gscanMock.format.calledOnce).to.be.true;

expect(knexMock.calledOnce).to.be.true;
Expand All @@ -88,7 +95,8 @@ describe('Unit: Tasks > Major Update > Data', function () {
client: 'mysql'
},
dir: '/var/www/ghost/',
versionFolder: 'versions/2.0.0/'
versionFolder: 'versions/2.0.0/',
version: '2.0.0'
});

expect(response.gscanReport.formatted).to.be.true;
Expand All @@ -98,6 +106,10 @@ describe('Unit: Tasks > Major Update > Data', function () {
expect(connection.raw.calledTwice).to.be.true;

expect(gscanMock.check.calledOnce).to.be.true;
expect(gscanMock.check.calledWithExactly(
'/var/www/ghost/content/themes/not-casper',
{checkVersion: 'v2'}
)).to.be.true;
expect(gscanMock.format.calledOnce).to.be.true;

expect(knexMock.calledOnce).to.be.true;
Expand All @@ -115,14 +127,19 @@ describe('Unit: Tasks > Major Update > Data', function () {
client: 'mysql'
},
dir: '/var/www/ghost/',
versionFolder: 'versions/2.0.0/'
versionFolder: 'versions/3.0.0/',
version: '3.0.0'
});
} catch (err) {
expect(err.message).to.eql('oops');
expect(connection.destroy.calledOnce).to.be.true;
expect(connection.raw.calledOnce).to.be.true;

expect(gscanMock.check.calledOnce).to.be.true;
expect(gscanMock.check.calledWithExactly(
'/var/www/ghost/versions/3.0.0/content/themes/casper',
{checkVersion: 'v3'}
)).to.be.true;
expect(gscanMock.format.called).to.be.false;

expect(knexMock.calledOnce).to.be.true;
Expand Down

0 comments on commit e74d1fc

Please sign in to comment.