Skip to content

imp(biomejs): upgrade Biomejs, fix patterns, don't use yarn workspaces #2015

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

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"files": {
"ignore": ["**/composer.json"]
"include": ["src/*/assets/src/**", "src/*/assets/test/**", "src/*/*.json", "src/*/*/md", "*.json", "*.md"],
"ignore": ["**/composer.json", "**/vendor", "**/node_modules"]
},
"linter": {
"rules": {
Expand All @@ -27,7 +29,7 @@
},
"javascript": {
"formatter": {
"trailingComma": "es5",
"trailingCommas": "es5",
"bracketSameLine": true,
"quoteStyle": "single"
}
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
"scripts": {
"build": "node bin/build_javascript.js && node bin/build_styles.js",
"test": "bin/run-vitest-all.sh",
"lint": "yarn workspaces run biome lint src test --apply",
"format": "biome format src/*/assets/src/*.ts src/*/assets/test/*.js {,src/*/}*.{json,md} --write",
"check-lint": "yarn workspaces run biome lint src test",
"check-format": "biome format src/*/assets/src/*.ts src/*/assets/test/*.js {,src/*/}*.{json,md}"
"lint": "biome lint --write",
"format": "biome format --write",
"check-lint": "biome lint",
"check-format": "biome format"
},
"devDependencies": {
"@babel/core": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"@babel/preset-react": "^7.15.8",
"@babel/preset-typescript": "^7.15.8",
"@biomejs/biome": "^1.7.3",
"@biomejs/biome": "^1.8.3",
"@rollup/plugin-commonjs": "^23.0.0",
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-typescript": "^10.0.0",
Expand Down
131 changes: 67 additions & 64 deletions src/Autocomplete/assets/test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* file that was distributed with this source code.
*/


import { Application } from '@hotwired/stimulus';
import { getByTestId, waitFor } from '@testing-library/dom';
import AutocompleteController, {
Expand All @@ -21,7 +20,7 @@ import { vi } from 'vitest';

const shortDelay = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));

const startAutocompleteTest = async (html: string): Promise<{ container: HTMLElement, tomSelect: TomSelect }> => {
const startAutocompleteTest = async (html: string): Promise<{ container: HTMLElement; tomSelect: TomSelect }> => {
const container = document.createElement('div');
container.innerHTML = html;

Expand All @@ -48,7 +47,7 @@ const startAutocompleteTest = async (html: string): Promise<{ container: HTMLEle
}

return { container, tomSelect };
}
};

const fetchMocker = createFetchMock(vi);
describe('AutocompleteController', () => {
Expand Down Expand Up @@ -80,7 +79,7 @@ describe('AutocompleteController', () => {
});

it('connect with ajax URL on a select element', async () => {
const { container, tomSelect} = await startAutocompleteTest(`
const { container, tomSelect } = await startAutocompleteTest(`
<label for="the-select">Items</label>
<select
id="the-select"
Expand All @@ -96,25 +95,25 @@ describe('AutocompleteController', () => {
results: [
{
value: 3,
text: 'salad'
text: 'salad',
},
]
}),
],
})
);

fetchMock.mockResponseOnce(
JSON.stringify({
results: [
{
value: 1,
text: 'pizza'
text: 'pizza',
},
{
value: 2,
text: 'popcorn'
}
]
}),
text: 'popcorn',
},
],
})
);

const controlInput = tomSelect.control_input;
Expand All @@ -140,7 +139,7 @@ describe('AutocompleteController', () => {
});

it('connect with ajax URL on an input element', async () => {
const { container, tomSelect} = await startAutocompleteTest(`
const { container, tomSelect } = await startAutocompleteTest(`
<label for="the-input">Items</label>
<input
id="the-input"
Expand All @@ -156,25 +155,25 @@ describe('AutocompleteController', () => {
results: [
{
value: 3,
text: 'salad'
text: 'salad',
},
],
}),
})
);

fetchMock.mockResponseOnce(
JSON.stringify({
results: [
{
value: 1,
text: 'pizza'
text: 'pizza',
},
{
value: 2,
text: 'popcorn'
text: 'popcorn',
},
],
}),
})
);

const controlInput = tomSelect.control_input;
Expand Down Expand Up @@ -233,8 +232,8 @@ describe('AutocompleteController', () => {
></select>
`);

expect(tomSelect.settings.shouldLoad('')).toBeTruthy()
})
expect(tomSelect.settings.shouldLoad('')).toBeTruthy();
});

it('default min-characters will always load after first load', async () => {
const { container, tomSelect } = await startAutocompleteTest(`
Expand All @@ -255,10 +254,10 @@ describe('AutocompleteController', () => {
results: [
{
value: 1,
text: 'pizza'
text: 'pizza',
},
],
}),
})
);
// wait for the initial Ajax request to finish
userEvent.click(controlInput);
Expand All @@ -280,14 +279,14 @@ describe('AutocompleteController', () => {
results: [
{
value: 1,
text: 'pizza'
text: 'pizza',
},
{
value: 2,
text: 'popcorn'
text: 'popcorn',
},
],
}),
})
);
controlInput.value = 'foo';
controlInput.dispatchEvent(new Event('input'));
Expand All @@ -302,18 +301,18 @@ describe('AutocompleteController', () => {
results: [
{
value: 1,
text: 'pizza'
text: 'pizza',
},
{
value: 2,
text: 'popcorn'
text: 'popcorn',
},
{
value: 3,
text: 'apples'
text: 'apples',
},
],
}),
})
);
controlInput.value = 'fo';
controlInput.dispatchEvent(new Event('input'));
Expand Down Expand Up @@ -350,19 +349,19 @@ describe('AutocompleteController', () => {
fetchMock.mockResponseOnce(
JSON.stringify({
results: [
{value: 1, text: 'dog1'},
{value: 2, text: 'dog2'},
{value: 3, text: 'dog3'},
{value: 4, text: 'dog4'},
{value: 5, text: 'dog5'},
{value: 6, text: 'dog6'},
{value: 7, text: 'dog7'},
{value: 8, text: 'dog8'},
{value: 9, text: 'dog9'},
{value: 10, text: 'dog10'},
{ value: 1, text: 'dog1' },
{ value: 2, text: 'dog2' },
{ value: 3, text: 'dog3' },
{ value: 4, text: 'dog4' },
{ value: 5, text: 'dog5' },
{ value: 6, text: 'dog6' },
{ value: 7, text: 'dog7' },
{ value: 8, text: 'dog8' },
{ value: 9, text: 'dog9' },
{ value: 10, text: 'dog10' },
],
next_page: '/path/to/autocomplete?query=&page=2'
}),
next_page: '/path/to/autocomplete?query=&page=2',
})
);

const controlInput = tomSelect.control_input;
Expand All @@ -380,11 +379,11 @@ describe('AutocompleteController', () => {
fetchMock.mockResponseOnce(
JSON.stringify({
results: [
{value: 11, text: 'dog11'},
{value: 12, text: 'dog12'},
{ value: 11, text: 'dog11' },
{ value: 12, text: 'dog12' },
],
next_page: null,
}),
})
);

// trigger a scroll, this will cause TomSelect to check "shouldLoadMore"
Expand Down Expand Up @@ -514,7 +513,7 @@ describe('AutocompleteController', () => {
<option value="8">dog8</option>
`;

let newTomSelect: TomSelect|null = null;
let newTomSelect: TomSelect | null = null;
container.addEventListener('autocomplete:connect', (event: any) => {
newTomSelect = (event.detail as AutocompleteConnectOptions).tomSelect;
});
Expand Down Expand Up @@ -570,8 +569,10 @@ describe('AutocompleteController', () => {
tomSelect.addItem('3');
tomSelect.addItem('2');
const getSelectedValues = () => {
return Array.from(selectElement.selectedOptions).map((option) => option.value).sort();
}
return Array.from(selectElement.selectedOptions)
.map((option) => option.value)
.sort();
};
const selectElement = getByTestId(container, 'main-element') as HTMLSelectElement;
expect(getSelectedValues()).toEqual(['2', '3']);

Expand Down Expand Up @@ -645,7 +646,7 @@ describe('AutocompleteController', () => {
const selectElement = getByTestId(container, 'main-element') as HTMLSelectElement;
expect(tomSelect.control_input.placeholder).toBe('Select a dog');

let newTomSelect: TomSelect|null = null;
let newTomSelect: TomSelect | null = null;
container.addEventListener('autocomplete:connect', (event: any) => {
newTomSelect = (event.detail as AutocompleteConnectOptions).tomSelect;
});
Expand Down Expand Up @@ -685,36 +686,36 @@ describe('AutocompleteController', () => {
{
group_by: ['Meat'],
value: 1,
text: 'Beef'
text: 'Beef',
},
{
group_by: ['Meat'],
value: 2,
text: 'Mutton'
text: 'Mutton',
},
{
group_by: ['starchy'],
value: 3,
text: 'Potatoes'
text: 'Potatoes',
},
{
group_by: ['starchy', 'Meat'],
value: 4,
text: 'chili con carne'
text: 'chili con carne',
},
],
optgroups: [
{
value: 'Meat',
label: 'Meat'
label: 'Meat',
},
{
value: 'starchy',
label: 'starchy'
label: 'starchy',
},
]
],
},
}),
})
);

fetchMock.mockResponseOnce(
Expand All @@ -724,22 +725,22 @@ describe('AutocompleteController', () => {
{
group_by: ['Meat'],
value: 1,
text: 'Beef'
text: 'Beef',
},
{
group_by: ['Meat'],
value: 2,
text: 'Mutton'
text: 'Mutton',
},
],
optgroups: [
{
value: 'Meat',
label: 'Meat'
label: 'Meat',
},
]
}
}),
],
},
})
);

const controlInput = tomSelect.control_input;
Expand Down Expand Up @@ -801,8 +802,10 @@ describe('AutocompleteController', () => {
tomSelect.addItem('3');

const getSelectedValues = () => {
return Array.from(selectElement.selectedOptions).map((option) => option.value).sort();
}
return Array.from(selectElement.selectedOptions)
.map((option) => option.value)
.sort();
};

const selectElement = getByTestId(container, 'main-element') as HTMLSelectElement;
expect(getSelectedValues()).toEqual(['2', '3']);
Expand Down
Loading