Skip to content

Commit

Permalink
refactor: types folder for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenybai committed Oct 27, 2021
1 parent 69d9aa3 commit 0846a39
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const config: Config.InitialOptions = {
collectCoverageFrom: [
'<rootDir>/src/**/*.ts',
'!src/**/index.*',
'!src/**/types.ts',
'!src/**/types/*',
'!src/**/schedule.ts',
'!src/**/jsx.ts',
'!src/**/patch.ts',
Expand Down
2 changes: 1 addition & 1 deletion scripts/dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ setTimeout(() => {
const style_css = `body { font-size: 2em; display: flex; justify-content: center; align-items: start; padding-top: 2em; font-family: Arial; }`;

if (!fs.existsSync('dev')) {
$`mkdir dev`;
await $`mkdir dev`;
await fs.writeFile('./dev/index.html', index_html);
await fs.writeFile('./dev/script.tsx', script_tsx);
await fs.writeFile('./dev/style.css', style_css);
Expand Down
2 changes: 1 addition & 1 deletion src/__test__/createElement.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createElement } from '../createElement';
import { m } from '../m';
import { OLD_VNODE_FIELD } from '../types';
import { OLD_VNODE_FIELD } from '../types/base';

describe('.createElement', () => {
it('should create Text', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__test__/m.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { className, DELETE, INSERT, kebab, m, ns, style, svg, UPDATE, toVNode } from '../m';
import { OLD_VNODE_FIELD, VDeltaOperationTypes } from '../types';
import { OLD_VNODE_FIELD, VDeltaOperationTypes } from '../types/base';

describe('.m', () => {
it('should create empty vnode with tag', () => {
Expand Down
7 changes: 3 additions & 4 deletions src/__test__/patch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { childrenDriver } from '../drivers/children';
import { propsDriver } from '../drivers/props';
import { DELETE, INSERT, m, UPDATE } from '../m';
import { compose, patch } from '../patch';
import { VFlags } from '../types';
import { VFlags } from '../types/base';

describe('.patch', () => {
it('should patch element with text as children', () => {
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('.patch', () => {
// VFlags.ONLY_KEYED_CHILDREN,
// );
// patch(el, newVNode3, newVNode2);
// expect(el).toEqual(createElement(newVNode3));
// expect(patch(el, newVNode3, newVNode2)).toEqual(createElement(newVNode3));

// const list4 = list3.reverse();
// const newVNode4 = m(
Expand All @@ -176,8 +176,7 @@ describe('.patch', () => {
// list4.map((item) => m('li', { key: item }, [item])),
// VFlags.ONLY_KEYED_CHILDREN,
// );
// patch(el, newVNode4, newVNode3);
// expect(el).toEqual(createElement(newVNode4));
// expect(patch(el, newVNode4, newVNode3)).toEqual(createElement(newVNode4));
});

it('should return new DOM node', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/createElement.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { propsDriver } from './drivers/props';
import { flushWorkStack } from './patch';
import { DOMNode, OLD_VNODE_FIELD, VNode } from './types';
import { DOMNode, OLD_VNODE_FIELD, VNode } from './types/base';

/**
* Creates an Element from a VNode
Expand Down
10 changes: 9 additions & 1 deletion src/drivers/children.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { createElement } from '../createElement';
import { patch } from '../patch';
import { DOMNode, VDelta, VDeltaOperationTypes, VElement, VFlags, VNode, VTask } from '../types';
import {
DOMNode,
VDelta,
VDeltaOperationTypes,
VElement,
VFlags,
VNode,
VTask,
} from '../types/base';

/**
* Diffs two VNode children and modifies the DOM node based on the necessary changes
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/props.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VElement, VProps, VTask } from '../types';
import { VElement, VProps, VTask } from '../types/base';

/**
* Diffs two VNode props and modifies the DOM node based on the necessary changes
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export * from './drivers/props';
export * from './m';
export * from './patch';
export * from './schedule';
export { OLD_VNODE_FIELD, VFlags } from './types';
export type { VDelta, VElement, VNode, VProps } from './types';
export { OLD_VNODE_FIELD, VFlags } from './types/base';
export type { VDelta, VElement, VNode, VProps } from './types/base';
4 changes: 2 additions & 2 deletions src/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Please update scripts/fix-jsx-runtime.mjs accordingly.

import { className, m, style, svg, VFlags } from './index';
import { VDelta, VNode, VProps } from './types';
import { JSX, JSXVNode, FC } from './types/jsx';
import { kebab } from './m';
import type { VDelta, VNode, VProps } from './types/base';
import type { FC, JSX, JSXVNode } from './types/jsx';

const h = (tag: string, props?: VProps, children?: JSXVNode[], delta?: VDelta) => {
let flag = VFlags.NO_CHILDREN;
Expand Down
2 changes: 1 addition & 1 deletion src/m.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
VFlags,
VNode,
VProps,
} from './types';
} from './types/base';

/**
* Attaches ns props to svg element
Expand Down
2 changes: 1 addition & 1 deletion src/patch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createElement } from './createElement';
import { childrenDriver } from './drivers/children';
import { propsDriver } from './drivers/props';
import { DOMNode, OLD_VNODE_FIELD, VCommit, VDriver, VElement, VNode, VTask } from './types';
import { DOMNode, OLD_VNODE_FIELD, VCommit, VDriver, VElement, VNode, VTask } from './types/base';

/**
* Passes all of the tasks in a given array to a given callback function sequentially.
Expand Down
2 changes: 1 addition & 1 deletion src/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VTask } from './types';
import { VTask } from './types/base';

const workStack: VTask[] = [];
const DEADLINE_THRESHOLD = 1000 / 60; // Minimum time to achieve 60 FPS
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/types/jsx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VDelta, VElement, VNode, VProps } from './index';
import type { VDelta, VElement, VNode, VProps } from './base';

export type JSXVNode = VNode | number | boolean | undefined | null;
export type FC = (props?: VProps, children?: JSXVNode[], delta?: VDelta) => VElement;
Expand Down

0 comments on commit 0846a39

Please sign in to comment.