Skip to content

Commit

Permalink
ci: format files on commit, validate commit msg
Browse files Browse the repository at this point in the history
  • Loading branch information
stas-nc committed Dec 20, 2024
1 parent 3556cff commit def8574
Show file tree
Hide file tree
Showing 10 changed files with 998 additions and 18 deletions.
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx --no -- commitlint --edit $1
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm run format:check
npx lint-staged
6 changes: 6 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('@commitlint/types').UserConfig}
*/
module.exports = {
extends: ['@commitlint/config-conventional'],
};
5 changes: 2 additions & 3 deletions ilc/client/BundleLoader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('BundleLoader', () => {
delete: sinon.stub(),
};
let registry;
let registryConfigurationStub;
const configRoot = getIlcConfigRoot();

const mockFactoryFn = () => {};
Expand Down Expand Up @@ -54,12 +53,12 @@ describe('BundleLoader', () => {
},
},
}).getConfig();
registryConfigurationStub = sinon.stub(configRoot, 'registryConfiguration').value(registry);
sinon.stub(configRoot, 'registryConfiguration').value(registry);
});

afterEach(() => {
SystemJs.import.reset();
registryConfigurationStub.restore();
sinon.stub(configRoot, 'registryConfiguration').restore();
});

describe('preloadApp()', () => {
Expand Down
2 changes: 1 addition & 1 deletion ilc/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class Client {
}

#configure() {
addNavigationHook((url) => (this.#transitionHooksExecutor.hasAccessTo(url) ? url : null));
addNavigationHook((url) => (this.#transitionHooksExecutor.shouldNavigate(url) ? url : null));
addNavigationHook((url) => this.#urlProcessor.process(url));

// TODO: window.ILC.importLibrary - calls bootstrap function with props (if supported), and returns exposed API
Expand Down
2 changes: 1 addition & 1 deletion ilc/client/TransitionHooksExecutor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class TransitionHooksExecutor {
this.#logger = logger;
}

hasAccessTo(url) {
shouldNavigate(url) {
const route = this.#router.match(url);
// This code is executed before the router change, so current = previous
const prevRoute = this.#router.getCurrentRoute();
Expand Down
10 changes: 5 additions & 5 deletions ilc/client/TransitionHooksExecutor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('TransitionHooksExecutor', () => {

const transitionHooksExecutor = new TransitionHooksExecutor(router, pluginManager, errorHandler, logger);

chai.expect(transitionHooksExecutor.hasAccessTo('/router/does/not/have/route')).to.be.true;
chai.expect(transitionHooksExecutor.shouldNavigate('/router/does/not/have/route')).to.be.true;
});

it(`if none of hooks returns "${actionTypes.stopNavigation}" or "${actionTypes.redirect}" action types`, () => {
Expand All @@ -87,7 +87,7 @@ describe('TransitionHooksExecutor', () => {

const transitionHooksExecutor = new TransitionHooksExecutor(router, pluginManager, errorHandler, logger);

chai.expect(transitionHooksExecutor.hasAccessTo(url)).to.be.true;
chai.expect(transitionHooksExecutor.shouldNavigate(url)).to.be.true;

for (const hook of hooks) {
sinon.assert.calledOnceWithExactly(hook, {
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('TransitionHooksExecutor', () => {

const transitionHooksExecutor = new TransitionHooksExecutor(router, pluginManager, errorHandler, logger);

chai.expect(transitionHooksExecutor.hasAccessTo(url)).to.be.false;
chai.expect(transitionHooksExecutor.shouldNavigate(url)).to.be.false;
sinon.assert.calledOnce(errorHandler);
chai.expect(errorHandler.getCall(0).args[0]).to.have.property('cause', error);
chai.expect(errorHandler.getCall(0).args[0]).to.be.instanceOf(TransitionHookError);
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('TransitionHooksExecutor', () => {

const transitionHooksExecutor = new TransitionHooksExecutor(router, pluginManager, errorHandler, logger);

chai.expect(transitionHooksExecutor.hasAccessTo(url)).to.be.false;
chai.expect(transitionHooksExecutor.shouldNavigate(url)).to.be.false;
sinon.assert.calledOnceWithExactly(
logger.info,
`ILC: Stopped navigation due to the Route Guard with index #${1}`,
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('TransitionHooksExecutor', () => {

const transitionHooksExecutor = new TransitionHooksExecutor(router, pluginManager, errorHandler, logger);

chai.expect(transitionHooksExecutor.hasAccessTo(url)).to.be.false;
chai.expect(transitionHooksExecutor.shouldNavigate(url)).to.be.false;
sinon.assert.notCalled(router.navigateToUrl);

for (const hook of [hooks[0], hooks[1]]) {
Expand Down
6 changes: 6 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('lint-staged').Config}
*/
module.exports = {
'*': 'prettier --ignore-unknown --write',
};
Loading

0 comments on commit def8574

Please sign in to comment.