Skip to content

Commit

Permalink
Merge pull request #213 from liferay/wincent/test-gaps
Browse files Browse the repository at this point in the history
test(monorepo): fill in test gaps
  • Loading branch information
wincent committed Oct 21, 2020
2 parents f7740da + e2a3437 commit 943b042
Show file tree
Hide file tree
Showing 23 changed files with 165 additions and 60 deletions.
3 changes: 2 additions & 1 deletion projects/js-toolkit/packages/generator-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"lint:fix": "liferay-workspace-scripts lint:fix",
"postversion": "liferay-workspace-scripts publish",
"prepublishOnly": "yarn build",
"preversion": "liferay-workspace-scripts ci"
"preversion": "liferay-workspace-scripts ci",
"test": "liferay-workspace-scripts test"
},
"version": "3.0.0-alpha.1"
}
3 changes: 2 additions & 1 deletion projects/js-toolkit/packages/js-toolkit-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"lint:fix": "liferay-workspace-scripts lint:fix",
"postversion": "liferay-workspace-scripts publish",
"prepublishOnly": "yarn build",
"preversion": "liferay-workspace-scripts ci"
"preversion": "liferay-workspace-scripts ci",
"test": "liferay-workspace-scripts test"
},
"version": "3.0.1-pre.0"
}
3 changes: 2 additions & 1 deletion projects/js-toolkit/packages/js-toolkit-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"lint:fix": "liferay-workspace-scripts lint:fix",
"postversion": "liferay-workspace-scripts publish",
"prepublishOnly": "yarn build",
"preversion": "liferay-workspace-scripts ci"
"preversion": "liferay-workspace-scripts ci",
"test": "liferay-workspace-scripts test"
},
"version": "3.0.0-alpha.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"lint:fix": "liferay-workspace-scripts lint:fix",
"postversion": "liferay-workspace-scripts publish",
"prepublishOnly": "yarn build",
"preversion": "liferay-workspace-scripts ci"
"preversion": "liferay-workspace-scripts ci",
"test": "liferay-workspace-scripts test"
},
"version": "3.0.0-alpha.1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* SPDX-FileCopyrightText: © 2017 Liferay, Inc. <https://liferay.com>
* SPDX-License-Identifier: LGPL-3.0-or-later
*/

import main from '../liferay-npm-bridge-generator';

describe('blinking light demo', () => {
it('exists', () => {
expect(typeof main).toBe('function');
});
});
3 changes: 2 additions & 1 deletion projects/js-toolkit/packages/npm-bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"lint:fix": "liferay-workspace-scripts lint:fix",
"postversion": "liferay-workspace-scripts publish",
"prepublishOnly": "yarn build",
"preversion": "liferay-workspace-scripts ci"
"preversion": "liferay-workspace-scripts ci",
"test": "liferay-workspace-scripts test"
},
"version": "3.0.1"
}
12 changes: 6 additions & 6 deletions projects/npm-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"private": true,
"scripts": {
"build": true,
"ci": "cd ../.. && yarn ci",
"format": "cd ../.. && yarn format",
"format:check": "cd ../.. && yarn format:check",
"lint": "cd ../.. && yarn lint",
"lint:fix": "cd ../.. && yarn lint:fix",
"ci": "liferay-workspace-scripts ci",
"format": "liferay-workspace-scripts format",
"format:check": "liferay-workspace-scripts format:check",
"lint": "liferay-workspace-scripts lint",
"lint:fix": "liferay-workspace-scripts lint:fix",
"preversion": "echo Cannot version private package; false",
"test": "cd ../.. && yarn test npm-tools"
"test": "liferay-workspace-scripts test"
},
"version": "0.1.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"postpublish": "echo '***'; echo 'NOTE: Remember to update and publish @liferay/npm-scripts'; echo '***'",
"postversion": "liferay-workspace-scripts publish",
"preversion": "liferay-workspace-scripts ci",
"test": "liferay-workspace-scripts test jest-junit-reporter"
"test": "liferay-workspace-scripts test"
},
"version": "1.2.0"
}
14 changes: 14 additions & 0 deletions projects/npm-tools/packages/js-insights/bin/liferay-js-insights.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node

/**
* SPDX-FileCopyrightText: © 2019 Liferay, Inc. <https://liferay.com>
* SPDX-License-Identifier: BSD-3-Clause
*/

const {main} = require('../src');

main().catch((error) => {
console.log(error); // eslint-disable-line no-console

process.exit(1);
});
5 changes: 4 additions & 1 deletion projects/npm-tools/packages/js-insights/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"author": "Liferay Frontend Infrastructure Team <pt-frontend-infrastructure@liferay.com>",
"bin": {
"liferay-js-insights": "./bin/liferay-js-insights.js"
},
"dependencies": {
"@babel/parser": "^7.6.0",
"@babel/traverse": "^7.6.2",
Expand All @@ -18,7 +21,7 @@
"usage"
],
"license": "BSD-3-Clause",
"main": "index.js",
"main": "src/index.js",
"name": "@liferay/js-insights",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function getModuleMeta(modulePath) {
* `npx @liferay/js-insights --json modules/private/apps`
* `npx @liferay/js-insights --airtable src/*.es.js`
*/
(async () => {
async function main() {
const data = [];
const requestedInsights =
argv.insights && typeof argv.insights === 'string'
Expand Down Expand Up @@ -111,4 +111,9 @@ async function getModuleMeta(modulePath) {
}

report(data, argv);
})();
}

module.exports = {
main,
parse,
};
14 changes: 14 additions & 0 deletions projects/npm-tools/packages/js-insights/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com>
* SPDX-License-Identifier: BSD-3-Clause
*/

const {parse} = require('../src');

describe('parse()', () => {
it('returns an AST', async () => {
const node = await parse('export const number = 1');

expect(node.type).toBe('File');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

require('../src');
const {main} = require('../src');

main();
2 changes: 1 addition & 1 deletion projects/npm-tools/packages/js-publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"lint:fix": "liferay-workspace-scripts lint:fix",
"postversion": "liferay-workspace-scripts publish",
"preversion": "liferay-workspace-scripts ci",
"test": "echo 'No tests currently defined for @liferay/js-publish'"
"test": "liferay-workspace-scripts test"
},
"version": "2.0.0"
}
89 changes: 47 additions & 42 deletions projects/npm-tools/packages/js-publish/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,60 @@ const run = require('./run');
let readline;

async function main() {
const branch = git('rev-parse', '--abbrev-ref', 'HEAD');
let exitStatus = 0;

if (branch !== 'master') {
panic('Not on "master" branch');
}
try {
const branch = git('rev-parse', '--abbrev-ref', 'HEAD');

if (branch !== 'master') {
panic('Not on "master" branch');
}

checkCleanWorktree();
checkCleanWorktree();

await checkYarnRc();
await checkYarnRc();

const pkg = JSON.parse(fs.readFileSync('package.json').toString());
const pkg = JSON.parse(fs.readFileSync('package.json').toString());

await checkPackage(pkg);
await checkPackage(pkg);

const remote = getRemote();
const remote = getRemote();

await confirm(`Push to ${remote}/master?`);
await confirm(`Push to ${remote}/master?`);

git('push', remote, 'master', '--follow-tags');
git('push', remote, 'master', '--follow-tags');

await runYarnPublish(pkg);
await runYarnPublish(pkg);

const url = `https://www.npmjs.com/package/${pkg.name}`;
const url = `https://www.npmjs.com/package/${pkg.name}`;

printBanner(
'Done! ✅',
'You can sanity-check that the package is correctly listed here:',
url
);
printBanner(
'Done! ✅',
'You can sanity-check that the package is correctly listed here:',
url
);
}
catch (error) {
printBanner(
'Failed to automatically publish package! ❌',
error.message,
'Please try publishing manually.',
'For reference, these are the publishing steps:',
'git rev-parse --abbrev-ref HEAD # expect "master"\n' +
'git diff --quiet # expect no output\n' +
'git push $REMOTE master --follow-tags # you will need to supply $REMOTE\n' +
'yarn publish'
);

exitStatus = 1;
}
finally {
if (readline) {
readline.close();
}

process.exit(exitStatus);
}
}

function panic(reason) {
Expand Down Expand Up @@ -190,27 +215,7 @@ async function runYarnPublish(pkg) {
run('yarn', 'publish', ...args);
}

let exitStatus = 0;

main()
.catch((error) => {
printBanner(
'Failed to automatically publish package! ❌',
error.message,
'Please try publishing manually.',
'For reference, these are the publishing steps:',
'git rev-parse --abbrev-ref HEAD # expect "master"\n' +
'git diff --quiet # expect no output\n' +
'git push $REMOTE master --follow-tags # you will need to supply $REMOTE\n' +
'yarn publish'
);

exitStatus = 1;
})
.finally(() => {
if (readline) {
readline.close();
}

process.exit(exitStatus);
});
module.exports = {
isPrereleaseVersion,
main,
};
16 changes: 16 additions & 0 deletions projects/npm-tools/packages/js-publish/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* SPDX-FileCopyrightText: © 2019 Liferay, Inc. <https://liferay.com>
* SPDX-License-Identifier: BSD-3-Clause
*/

const {isPrereleaseVersion} = require('../src');

describe('isPrereleaseVersion()', () => {
it('returns true when there is a hyphen in the version number', () => {
expect(isPrereleaseVersion({version: '1.0.0-pre.0'})).toBe(true);
});

it('returns false when there is no hyphen in the version number', () => {
expect(isPrereleaseVersion({version: '1.0.0'})).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"postpublish": "echo '***'; echo 'NOTE: Remember to update and publish @liferay/npm-scripts'; echo '***'",
"postversion": "liferay-workspace-scripts publish",
"preversion": "liferay-workspace-scripts ci",
"test": "echo 'No tests currently defined for @liferay/npm-bundler-preset-liferay-dev'"
"test": "liferay-workspace-scripts test"
},
"version": "4.6.5"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com>
* SPDX-License-Identifier: BSD-3-Clause
*/

const fs = require('fs');
const path = require('path');

describe('config.json', () => {
it('is valid JSON', () => {
const json = fs.readFileSync(
path.join(__dirname, '..', 'config.json'),
'utf8'
);

const parsed = JSON.parse(json);

expect(parsed).toEqual(
expect.objectContaining({
'*': expect.any(Object),
'/': expect.any(Object),
config: expect.any(Object),
exclude: expect.any(Object),
output: expect.any(String),
rules: expect.any(Array),
})
);
});
});

0 comments on commit 943b042

Please sign in to comment.