Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Sep 25, 2019
1 parent edd4ebc commit da7cfa5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ module.exports = {
},
],
},
overrides: [
{
files: ['./update-package.js'],
rules: {
'no-magic-numbers': "off",
'no-console': "off",
},
},
],
};
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
},
transformIgnorePatterns: ['node_modules/(?!(babel-jest|jest-vue-preprocessor)/)'],
moduleNameMapper: {
'/myparcel-js-sdk(?:/.+)+?$': '<rootDir>/tests/__mocks__/myparcel-js-sdk.js',
'^@myparcel/sdk(?:/.+)+?$': '<rootDir>/tests/__mocks__/myparcel-js-sdk.js',
'^@/(.*)$': '<rootDir>/src/$1',
},
snapshotSerializers: ['jest-serializer-vue'],
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ describe('The delivery options module', () => {
});
app = shallowMount(App);

// hasValidAddress is false as cc is missing.
expect(app.vm.hasSomethingToShow).toBe(false);

// hasValidAddress is true as cc is allowed for current platform.
app.vm.$configBus.$data.address = defaultAddress[MYPARCEL];
expect(app.vm.hasSomethingToShow).toBe(true);
});
});
17 changes: 9 additions & 8 deletions update-package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const packageJson = require('./package.json');
const exec = require('child_process').exec;
const { exec } = require('child_process');

const run = async(command) => {
const run = (command) => {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error !== null) {
Expand All @@ -14,25 +14,26 @@ const run = async(command) => {
};

async function execute() {
const [path, file, ...arguments] = process.argv;
const packageName = arguments[0] || packageJson.name;
// Ignore path and file arguments.
const [, , ...args] = process.argv;
const packageName = args[0] || packageJson.name;

const [latestVersion, currentVersion] = await Promise.all([
run(`npm view ${packageName} version`).catch(() => false),
run(`npm show ${packageName} version`).catch(() => false)
run(`npm show ${packageName} version`).catch(() => false),
]);

if (!latestVersion || !currentVersion) {
console.log(`${packageName}: Package not found.`);
return;
}

if (latestVersion !== currentVersion) {
if (latestVersion === currentVersion) {
console.log(`${packageName}: Package up to date!`);
} else {
await run(`npm install ${packageName}@latest`).then(() => {
console.log(`${packageName}: Updated package from ${currentVersion} to ${latestVersion}.`);
});
} else {
console.log(`${packageName}: Package up to date!`);
}
}

Expand Down

0 comments on commit da7cfa5

Please sign in to comment.