Skip to content

Commit

Permalink
migrated all tests to use vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek-17h committed Feb 12, 2025
1 parent f9c3d3c commit fd6396b
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 117 deletions.
11 changes: 6 additions & 5 deletions packages/volto/__tests__/create-addons-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getAddonsLoaderCode,
nameFromPackage,
} from '@plone/registry/create-addons-loader';
import { describe, expect } from 'vitest';
import jiti from 'jiti';

describe('create-addons-loader code generation', () => {
test('no addon creates simple loader, default = no loadProjectConfig', () => {
Expand Down Expand Up @@ -166,9 +166,10 @@ describe('create-addons-loader default name generation', () => {
});
});

const _import = jiti(import.meta.url, { esmResolve: true });

function transpile(fpath) {
const code = fs.readFileSync(fpath, 'utf-8');
// console.log('original code', code);
const output = transform(code, {
root: '.',
plugins: ['@babel/plugin-transform-modules-commonjs'],
Expand All @@ -179,18 +180,18 @@ function transpile(fpath) {
function makeAddonLoader(addons, load = true) {
addons = addons.map((name) =>
name.includes(':')
? `${require.resolve(name.split(':')[0])}:${name.substring(
? `${_import.resolve(name.split(':')[0])}:${name.substring(
name.indexOf(':') + 1,
name.length,
)}`
: require.resolve(name),
: _import.resolve(name),
);

const loaderPath = createAddonsLoader(addons);
transpile(loaderPath);

if (load) {
return require(loaderPath).default;
return _import(loaderPath).default;
} else {
return loaderPath;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/volto/__tests__/volto-slate/deserialize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { deserialize } from '@plone/volto-slate/editor/deserialize';
import * as htmlUtils from '@plone/volto-slate/editor/utils';
import { makeEditor } from '@plone/volto-slate/utils/editor';
import installSlate from '@plone/volto-slate/index';
import { it, describe, expect } from 'vitest';

vi.mock('@plone/volto-slate/editor/less/editor.less', () => ({}));

const tojson = (html) => {
const parsed = new JSDOM(html);
Expand Down
1 change: 1 addition & 0 deletions packages/volto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@
"jest": "26.6.3",
"jest-environment-jsdom": "^26",
"jest-file": "1.0.0",
"jiti": "^2.4.2",
"jsdom": "^16.7.0",
"jsonwebtoken": "9.0.0",
"less": "3.11.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ exports[`SelectFacet > renders a facet component with select dropdown 1`] = `
class="react-select__control css-1i6qwov-control"
>
<div
class="react-select__value-container css-12ms9px-ValueContainer"
class="react-select__value-container css-jrhyj0"
>
<div
class="react-select__placeholder css-1wa3eu0-placeholder"
>
Test Facet
</div>
<div
class="css-b8ldur-Input"
class="css-1g6gooi"
>
<div
class="react-select__input"
Expand All @@ -48,14 +48,14 @@ exports[`SelectFacet > renders a facet component with select dropdown 1`] = `
</div>
</div>
<div
class="react-select__indicators css-1hb7zxy-IndicatorsContainer"
class="react-select__indicators css-1wy0on6"
>
<span
class="react-select__indicator-separator css-6fp5c8-indicatorSeparator"
/>
<div
aria-hidden="true"
class="react-select__indicator react-select__dropdown-indicator css-1ib5zur-DropdownIndicator"
class="react-select__indicator react-select__dropdown-indicator css-z7kouv"
>
<svg
class="icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ exports[`No 'No value' option when default value is 0 1`] = `
class="react-select__control react-select__control--is-focused react-select__control--menu-is-open css-1ptmoe7-control"
>
<div
class="react-select__value-container react-select__value-container--is-multi css-1a9cv00-ValueContainer"
class="react-select__value-container react-select__value-container--is-multi css-1dvrfad"
>
<div
class="react-select__placeholder css-1wa3eu0-placeholder"
>
Select…
</div>
<div
class="css-b8ldur-Input"
class="css-1g6gooi"
>
<div
class="react-select__input"
Expand All @@ -85,14 +85,14 @@ exports[`No 'No value' option when default value is 0 1`] = `
</div>
</div>
<div
class="react-select__indicators css-1hb7zxy-IndicatorsContainer"
class="react-select__indicators css-1wy0on6"
>
<span
class="react-select__indicator-separator css-6fp5c8-indicatorSeparator"
/>
<div
aria-hidden="true"
class="react-select__indicator react-select__dropdown-indicator css-7hdh9a-DropdownIndicator"
class="react-select__indicator react-select__dropdown-indicator css-9t8fgp"
>
<svg
class="icon"
Expand All @@ -112,7 +112,7 @@ exports[`No 'No value' option when default value is 0 1`] = `
class="react-select__menu css-109xf7j-menu"
>
<div
class="react-select__menu-list react-select__menu-list--is-multi css-4ljt47-MenuList"
class="react-select__menu-list react-select__menu-list--is-multi css-11unzgr"
>
<div
class="react-select__option react-select__option--is-focused css-p2m0aa-option"
Expand Down Expand Up @@ -221,15 +221,15 @@ exports[`renders an array widget component 1`] = `
onTouchEnd={[Function]}
>
<div
className="react-select__value-container react-select__value-container--is-multi css-1a9cv00-ValueContainer"
className="react-select__value-container react-select__value-container--is-multi css-1dvrfad"
>
<div
className="react-select__placeholder css-1wa3eu0-placeholder"
>
Select…
</div>
<div
className="css-b8ldur-Input"
className="css-1g6gooi"
>
<div
className="react-select__input"
Expand Down Expand Up @@ -286,14 +286,14 @@ exports[`renders an array widget component 1`] = `
</div>
</div>
<div
className="react-select__indicators css-1hb7zxy-IndicatorsContainer"
className="react-select__indicators css-1wy0on6"
>
<span
className="react-select__indicator-separator css-6fp5c8-indicatorSeparator"
/>
<div
aria-hidden="true"
className="react-select__indicator react-select__dropdown-indicator css-7hdh9a-DropdownIndicator"
className="react-select__indicator react-select__dropdown-indicator css-9t8fgp"
onMouseDown={[Function]}
onTouchEnd={[Function]}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,22 @@ exports[`renders a datetime widget component 1`] = `
</div>
<div
class="ui input time-input"
/>
>
<span
class="rc-time-picker"
>
<input
class="rc-time-picker-input"
id="my-field-time"
placeholder="Time"
type="text"
value="12:00 AM"
/>
<span
class="rc-time-picker-icon"
/>
</span>
</div>
<button
class="item ui noborder button"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,34 @@ exports[`FileWidget > renders an empty file widget component 1`] = `
<div
class="eight wide column"
>
<div
class="file-widget-dropzone"
tabindex="0"
>
<div
class="dropzone-placeholder"
>
<p
class="dropzone-text"
>
Drop file here to upload a new file
</p>
</div>
<label
class="label-file-widget-input"
>
Choose a file
</label>
<input
autocomplete="off"
id="field-my-field"
multiple=""
name="my-field"
style="display: none;"
tabindex="-1"
type="file"
/>
</div>
<div
class="field-file-name"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,34 @@ exports[`RegistryImageWidget > renders an empty file widget component 1`] = `
<div
class="eight wide column"
>
<div
class="file-widget-dropzone"
tabindex="0"
>
<div
class="dropzone-placeholder"
>
<p
class="dropzone-text"
>
Drop file here to upload a new file
</p>
</div>
<label
class="label-file-widget-input"
>
Choose a file
</label>
<input
autocomplete="off"
id="field-my-field"
multiple=""
name="my-field"
style="display: none;"
tabindex="-1"
type="file"
/>
</div>
<div
class="field-file-name"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ exports[`renders a select widget component 1`] = `
class="react-select__control css-1ard45z-control"
>
<div
class="react-select__value-container react-select__value-container--is-multi css-1a9cv00-ValueContainer"
class="react-select__value-container react-select__value-container--is-multi css-1dvrfad"
>
<div
class="react-select__placeholder css-1wa3eu0-placeholder"
>
Select…
</div>
<div
class="css-b8ldur-Input"
class="css-1g6gooi"
>
<div
class="react-select__input"
Expand All @@ -75,14 +75,14 @@ exports[`renders a select widget component 1`] = `
</div>
</div>
<div
class="react-select__indicators css-1hb7zxy-IndicatorsContainer"
class="react-select__indicators css-1wy0on6"
>
<span
class="react-select__indicator-separator css-6fp5c8-indicatorSeparator"
/>
<div
aria-hidden="true"
class="react-select__indicator react-select__dropdown-indicator css-7hdh9a-DropdownIndicator"
class="react-select__indicator react-select__dropdown-indicator css-9t8fgp"
>
<svg
class="icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ exports[`No 'No value' option when default value is 0 1`] = `
class="react-select__control react-select__control--is-focused react-select__control--menu-is-open css-1ptmoe7-control"
>
<div
class="react-select__value-container react-select__value-container--has-value css-1a9cv00-ValueContainer"
class="react-select__value-container react-select__value-container--has-value css-1dvrfad"
>
<div
class="react-select__single-value css-1uccc91-singleValue"
>
None
</div>
<div
class="css-b8ldur-Input"
class="css-1g6gooi"
>
<div
class="react-select__input"
Expand All @@ -85,11 +85,11 @@ exports[`No 'No value' option when default value is 0 1`] = `
</div>
</div>
<div
class="react-select__indicators css-1hb7zxy-IndicatorsContainer"
class="react-select__indicators css-1wy0on6"
>
<div
aria-hidden="true"
class="react-select__indicator react-select__clear-indicator css-1v154vq-ClearIndicator"
class="react-select__indicator react-select__clear-indicator css-mszz6t"
>
<svg
class="icon"
Expand All @@ -108,7 +108,7 @@ exports[`No 'No value' option when default value is 0 1`] = `
/>
<div
aria-hidden="true"
class="react-select__indicator react-select__dropdown-indicator css-7hdh9a-DropdownIndicator"
class="react-select__indicator react-select__dropdown-indicator css-9t8fgp"
>
<svg
class="icon"
Expand All @@ -128,7 +128,7 @@ exports[`No 'No value' option when default value is 0 1`] = `
class="react-select__menu css-109xf7j-menu"
>
<div
class="react-select__menu-list css-4ljt47-MenuList"
class="react-select__menu-list css-11unzgr"
>
<div
class="react-select__option react-select__option--is-focused react-select__option--is-selected css-zq2nh-option"
Expand Down Expand Up @@ -240,15 +240,15 @@ exports[`renders a select widget component 1`] = `
class="react-select__control css-1ard45z-control"
>
<div
class="react-select__value-container css-1a9cv00-ValueContainer"
class="react-select__value-container css-1dvrfad"
>
<div
class="react-select__placeholder css-1wa3eu0-placeholder"
>
Select…
</div>
<div
class="css-b8ldur-Input"
class="css-1g6gooi"
>
<div
class="react-select__input"
Expand All @@ -274,14 +274,14 @@ exports[`renders a select widget component 1`] = `
</div>
</div>
<div
class="react-select__indicators css-1hb7zxy-IndicatorsContainer"
class="react-select__indicators css-1wy0on6"
>
<span
class="react-select__indicator-separator css-6fp5c8-indicatorSeparator"
/>
<div
aria-hidden="true"
class="react-select__indicator react-select__dropdown-indicator css-7hdh9a-DropdownIndicator"
class="react-select__indicator react-select__dropdown-indicator css-9t8fgp"
>
<svg
class="icon"
Expand Down
Loading

0 comments on commit fd6396b

Please sign in to comment.