Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node.js upgrade to v18 along with dependency upgrades and linting fixes #645

Open
wants to merge 11 commits into
base: release-v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 10.x
node-version: 18.x

- name: Cache Node.js modules
uses: actions/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '10.x'
node-version: '18.x'
AlexVelezLl marked this conversation as resolved.
Show resolved Hide resolved
- name: Cache Node.js modules
uses: actions/cache@v4
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ docs/jsdocs.js
# IDE
.idea
kolibri-design-system.iml

# env
.envrc
.python-version
4 changes: 2 additions & 2 deletions dev_docs/01_getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ The design system has two primary parts, the UI component library [`/lib`](../li

## Prerequisites

- Node.js 10.x (see [Node Version Manager](https://github.com/nvm-sh/nvm))
- Yarn 1.x
- Node.js 18.x (see [Node Version Manager](https://github.com/nvm-sh/nvm))
- Yarn >=1.22.22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now when I run yarn lint, yarn dev I get this error because I dont have pnpm installed:

> yarn lint
yarn run v1.22.22
$ kolibri-tools lint --pattern '**/*.{js,vue,scss,less,css}' --ignore '**/node_modules/**,**/.nuxt/**,**/dist/**,**/lib/KIcon/precompiled-icons/**,**/lib/keen/**,**/docs/environment.js,**/docs/jsdocs.js'

Kolibri CLI: Error: Command failed: "pnpm --version"

stderr:
Volta error: Could not find executable "pnpm"

Use `volta install` to add a package to your toolchain (see `volta help install` for more info).
Error details written to /home/alexvelezll/.volta/log/volta-error-2024-05-27_11_10_15.764.log


original error message:
Command failed: pnpm --version
Volta error: Could not find executable "pnpm"

Use `volta install` to add a package to your toolchain (see `volta help install` for more info).
Error details written to /home/alexvelezll/.volta/log/volta-error-2024-05-27_11_10_15.764.log


error Command failed with exit code 1.

Does the new version of kolibri-tools require pnpm to be installed? If so I think we need to add this to our prerequisites.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no requirement on pnpm-- nothing in regards to that has changed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you previously run a corepack command on your system?

I don't think this will resolve the issue, but you could try adding export SKIP_YARN_COREPACK_CHECK=1 to your terminal env.

Copy link
Member

@AlexVelezLl AlexVelezLl May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, no, that didn't solve it. It's weird because I tried to run it on my Windows machine, where I also don't have Pnpm, and it worked there 🤔

In my Ubuntu machine I finally installed pnpm using volta install pnpm and then yarn lint worked.


## Troubleshooting

Expand Down
3 changes: 3 additions & 0 deletions docs/assets/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ code {

a code {
color: $link-color;

&:hover {
color: $link-hover-color;
}
Expand All @@ -44,6 +45,7 @@ a {

&:hover {
color: $link-hover-color;

svg {
fill: $link-hover-color;
}
Expand All @@ -70,6 +72,7 @@ html {
html {
box-sizing: border-box;
}

*,
*::before,
*::after {
Expand Down
2 changes: 2 additions & 0 deletions docs/common/DocsAnchorTarget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
required: true,
validator(value) {
if (!value.startsWith('#')) {
// eslint-disable-next-line no-console
console.error(`'anchor' prop value '${value}' must start with a '#'`);
return false;
}
if (!value.match(/^#[\w\-.:]*$/)) {
// eslint-disable-next-line no-console
console.error(`'anchor' prop value '${value}' invalid`);
return false;
}
Expand Down
1 change: 1 addition & 0 deletions docs/common/DocsFilter/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
font-size: 12px;
border: 1px solid $border-color;
border-radius: 4px;

&::placeholder {
color: $border-color;
}
Expand Down
4 changes: 4 additions & 0 deletions docs/common/DocsGithubLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
function validator(value) {
if (typeof value === 'string') {
if (value.startsWith('#')) {
// eslint-disable-next-line no-console
console.error(`PR or issue number '${value}' should not start with a '#'`);
return false;
}
if (!value.match(/^\d+$/)) {
// eslint-disable-next-line no-console
console.error(`PR or issue number '${value}' invalid`);
return false;
}
Expand Down Expand Up @@ -78,12 +80,14 @@
return `https://github.com/learningequality/kolibri-design-system/pull/${this.pull}`;
if (this.issue)
return `https://github.com/learningequality/kolibri-design-system/issues/${this.issue}`;
// eslint-disable-next-line no-console
console.error(`No URL, PR, or issue provided`);
return undefined;
},
},
mounted() {
if (this.pull && this.issue) {
// eslint-disable-next-line no-console
console.warn("Pass either 'pull' or 'issue', not both");
}
},
Expand Down
2 changes: 1 addition & 1 deletion docs/common/DocsPageSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<script>

const consola = require('consola');
import consola from 'consola';

export default {
name: 'DocsPageSection',
Expand Down
2 changes: 1 addition & 1 deletion docs/common/DocsPageTemplate/SideNav/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
return termList(this.filterText);
},
visibleTableOfContents() {
let toc = [];
const toc = [];
for (const section of tableOfContents) {
// if the section title matches, add the entire thing
if (matches(this.terms, section.title)) {
Expand Down
1 change: 1 addition & 0 deletions docs/pages/principles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
.description {
font-size: 18px;
}

li {
font-size: 14px;
color: #616161;
Expand Down
2 changes: 1 addition & 1 deletion jest.conf/fileMock.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// As recommended by https://jestjs.io/docs/en/webpack#handling-static-assets

module.exports = 'test-file-stub';
export default 'test-file-stub';
10 changes: 6 additions & 4 deletions jest.conf/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path');
const path = require('node:path');

const moduleNameMapper = {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|css)$': path.resolve(
Expand All @@ -12,10 +12,12 @@ module.exports = {
moduleFileExtensions: ['js', 'json', 'vue'],
moduleNameMapper,
testEnvironment: 'jsdom',
testURL: 'http://kolibri.time',
testEnvironmentOptions: {
url: 'http://kolibri.time',
},
transform: {
'^.+\\.js$': 'babel-jest',
'^.+\\.vue$': 'vue-jest',
'^.+\\.js$': require.resolve('babel-jest'),
'^.+\\.vue$': require.resolve('vue-jest'),
},
snapshotSerializers: ['jest-serializer-vue'],
globals: {
Expand Down
3 changes: 3 additions & 0 deletions jest.conf/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import '@testing-library/jest-dom';
import * as Aphrodite from 'aphrodite';
import * as AphroditeNoImportant from 'aphrodite/no-important';

// eslint-disable-next-line import/no-unresolved
import 'mock-match-media/jest-setup';

import Vue from 'vue';
import VueRouter from 'vue-router';
import VueIntl from 'vue-intl';
Expand Down
1 change: 0 additions & 1 deletion jest.conf/testUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'mock-match-media/jest-setup.cjs';
import { setMedia } from 'mock-match-media';

export const resizeWindow = (width, height = 768) => {
Expand Down
21 changes: 14 additions & 7 deletions lib/KDateRange/KDateInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
:ref="inputRef"
:value="value"
type="date"
pattern="\d{4}-\d{2}-\d{2}"
pattern="\d{4}-\d{2}-\d{2}"
:label="legendText"
autoComplete="off"
:invalid="Boolean(errorMessage)"
:showInvalidText="Boolean(errorMessage)"
:invalidText="errorMessage"
:floatingLabel="false"
@input="handleInput"
/>
/>
<span class="k-date-vhidden">
<span v-if="value" :id="inputId">
{{ dateDescription }}
Expand All @@ -28,9 +28,10 @@

<script>

import { v4 as uuidv4 } from 'uuid';
import KTextBox from '../KTextbox';

let uuid = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we used the same approach from another component (instead of using uuid library), could there be any conflicts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if the ID prefix wasn't already unique


export default {
name: 'KDateInput',
components: {
Expand All @@ -54,6 +55,11 @@
default: null,
},
},
data() {
return {
uuid: 0,
};
},
computed: {
dateDescription() {
if (this.value) {
Expand All @@ -74,13 +80,14 @@
},
inputId() {
if (this.value) {
return `DateDesc_${uuidv4()
.split('-')
.pop()}`;
return `DateDesc_${this.uuid}`;
}
return '';
},
},
beforeCreate() {
this.uuid = String(uuid++);
},
mounted() {
this.$nextTick(() => {
const inputs = document.querySelectorAll('input[type = date]');
Expand Down Expand Up @@ -148,4 +155,4 @@
}
}

</style>
</style>
6 changes: 3 additions & 3 deletions lib/KDropdownMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@
const lastChild = menuElements[menuElements.length - 1];
const popoverIsOpen = popover.clientWidth > 0 && popover.clientHeight > 0;
// set current element and its siblings
let focusedElement = document.activeElement;
let sibling = focusedElement.nextElementSibling;
let prevSibling = focusedElement.previousElementSibling;
const focusedElement = document.activeElement;
const sibling = focusedElement.nextElementSibling;
const prevSibling = focusedElement.previousElementSibling;

// manage rotating through the options using arrow keys
// UP arrow: .keyCode is depricated and should used only as a fallback
Expand Down
1 change: 1 addition & 0 deletions lib/KIcon/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
},
mounted() {
if (KolibriIcons[this.icon].fixedColor && this.color) {
// eslint-disable-next-line no-console
console.error(
`KIcon: ${this.icon} color property will not be applied because the icon has a fixed color.`
);
Expand Down
71 changes: 43 additions & 28 deletions lib/KImg/__tests__/KImg.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { shallowMount } from '@vue/test-utils';
import KImg from '../';

function makeWrapper({ propsData = {} } = {}) {
return shallowMount(KImg, { propsData });
function makeWrapper(opts) {
return shallowMount(KImg, opts);
}

describe('KImg', () => {
it(`renders without any errors when a valid 'src' and 'altText' are provided`, () => {
const error = jest.fn();
const wrapper = makeWrapper({
propsData: { src: '/le-logo.svg', altText: 'LE logo' },
listeners: { error },
});

expect(wrapper.exists()).toBe(true);
expect(error).not.toHaveBeenCalled();

const img = wrapper.find('img');
expect(img.exists()).toBe(true);
Expand All @@ -20,20 +23,26 @@ describe('KImg', () => {
});

it(`throws an error when no 'altText' is provided`, () => {
expect(() =>
makeWrapper({
propsData: { src: '/le-logo.svg', altText: undefined },
})
).toThrow();
const error = jest.fn();
makeWrapper({
propsData: { src: '/le-logo.svg', altText: undefined },
listeners: { error },
});
expect(error).toHaveBeenCalled();
expect(error.mock.calls[0][0]).toBeInstanceOf(Error);
expect(error.mock.calls[0][0].message).toBe(
'Missing required prop - provide altText or indicate isDecorative'
);
});

describe(`when no 'altText' is provided and it is a decorative image`, () => {
it(`does not throw an error`, () => {
expect(() =>
makeWrapper({
propsData: { src: '/le-logo.svg', altText: undefined, isDecorative: true },
})
).not.toThrow();
const error = jest.fn();
makeWrapper({
propsData: { src: '/le-logo.svg', altText: undefined, isDecorative: true },
listeners: { error },
});
expect(error).not.toHaveBeenCalled();
});

it(`sets 'alt' attribute to an empty string`, () => {
Expand All @@ -46,32 +55,38 @@ describe('KImg', () => {
});

it(`throws an error when 'aspectRatio' has an invalid format`, () => {
expect(() =>
makeWrapper({
propsData: { src: '/le-logo.svg', altText: 'LE logo', aspectRatio: '16/9' },
})
).toThrow();
const error = jest.fn();
makeWrapper({
propsData: { src: '/le-logo.svg', altText: 'LE logo', aspectRatio: '16/9' },
listeners: { error },
});
expect(error).toHaveBeenCalled();
expect(error.mock.calls[0][0]).toBeInstanceOf(Error);
expect(error.mock.calls[0][0].message).toBe('Invalid aspect ratio provided: 16/9');
});

it(`doesn't throw an error when 'aspectRatio' has a valid format`, () => {
expect(() =>
makeWrapper({
propsData: { src: '/le-logo.svg', altText: 'LE logo', aspectRatio: '16:9' },
})
).not.toThrow();
const error = jest.fn();
makeWrapper({
propsData: { src: '/le-logo.svg', altText: 'LE logo', aspectRatio: '16:9' },
listeners: { error },
});
expect(error).not.toHaveBeenCalled();
});

it(`emits an 'error' event when there is an error in loading the image`, () => {
it(`emits an 'error' event when there is an error in loading the image`, async () => {
const error = jest.fn();
const wrapper = makeWrapper({
propsData: { src: '/le-logo.svg', altText: 'LE logo' },
listeners: { error },
});

// Manually trigger the onError method to simulate the image load failure
wrapper.vm.onError(new Event('error'));
const e = new Event('error');
wrapper.vm.onError(e);

// Check if the "error" event has been emitted with the DOM event payload
const emittedEvent = wrapper.emitted().error;
expect(emittedEvent).toBeTruthy();
expect(emittedEvent[0][0]).toBeInstanceOf(Event);
expect(error).toHaveBeenCalled();
expect(error.mock.calls[0][0]).toBeInstanceOf(Event);
expect(error.mock.calls[0][0]).toEqual(e);
});
});
Loading