Skip to content

Commit

Permalink
chore: move tests to node (#10113)
Browse files Browse the repository at this point in the history
* chore: move tests to node

* forgot to rename it

* Update packages/astro/test/solid-component.nodetest.js

Co-authored-by: Arsh <69170106+lilnasy@users.noreply.github.com>

* test hanging, let's skip it

---------

Co-authored-by: Arsh <69170106+lilnasy@users.noreply.github.com>
  • Loading branch information
ematipico and lilnasy authored Feb 14, 2024
1 parent 476b79a commit ef080d5
Show file tree
Hide file tree
Showing 22 changed files with 419 additions and 412 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { describe, it, before } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

Expand All @@ -25,11 +26,11 @@ describe('scopedStyleStrategy', () => {
});

it('includes :where pseudo-selector', () => {
expect(stylesheet).to.match(/:where/);
assert.match(stylesheet, /:where/);
});

it('does not includes the class name directly in the selector', () => {
expect(stylesheet).to.not.match(/h1\.astro/);
assert.doesNotMatch(stylesheet, /h1\.astro/);
});
});

Expand All @@ -55,11 +56,11 @@ describe('scopedStyleStrategy', () => {
});

it('does not include :where pseudo-selector', () => {
expect(stylesheet).to.not.match(/:where/);
assert.doesNotMatch(stylesheet, /:where/);
});

it('includes the class name directly in the selector', () => {
expect(stylesheet).to.match(/h1\.astro/);
assert.match(stylesheet, /h1\.astro/);
});
});

Expand All @@ -84,15 +85,15 @@ describe('scopedStyleStrategy', () => {
});

it('does not include :where pseudo-selector', () => {
expect(stylesheet).to.not.match(/:where/);
assert.doesNotMatch(stylesheet, /:where/);
});

it('does not include the class name directly in the selector', () => {
expect(stylesheet).to.not.match(/h1\.astro/);
assert.doesNotMatch(stylesheet, /h1\.astro/);
});

it('includes the data attribute hash', () => {
expect(stylesheet).to.include('h1[data-astro-cid-');
assert.equal(stylesheet.includes('h1[data-astro-cid-'), true);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,113 +1,114 @@
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { serializeProps } from '../dist/runtime/server/serialize.js';

describe('serialize', () => {
it('serializes undefined', () => {
const input = { a: undefined };
const output = `{"a":[0]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes null', () => {
const input = { a: null };
const output = `{"a":[0,null]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes a boolean', () => {
const input = { a: false };
const output = `{"a":[0,false]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes a number', () => {
const input = { a: 1 };
const output = `{"a":[0,1]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes a string', () => {
const input = { a: 'b' };
const output = `{"a":[0,"b"]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes an object', () => {
const input = { a: { b: 'c' } };
const output = `{"a":[0,{"b":[0,"c"]}]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes an array', () => {
const input = { a: [0] };
const output = `{"a":[1,[[0,0]]]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('can serialize deeply nested data without quadratic quote escaping', () => {
const input = { a: [{ b: [{ c: [{ d: [{ e: [{ f: [{ g: ['leaf'] }] }] }] }] }] }] };
const output =
'{"a":[1,[[0,{"b":[1,[[0,{"c":[1,[[0,{"d":[1,[[0,{"e":[1,[[0,{"f":[1,[[0,{"g":[1,[[0,"leaf"]]]}]]]}]]]}]]]}]]]}]]]}]]]}';
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes a regular expression', () => {
const input = { a: /b/ };
const output = `{"a":[2,"b"]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes a Date', () => {
const input = { a: new Date(0) };
const output = `{"a":[3,"1970-01-01T00:00:00.000Z"]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes a Map', () => {
const input = { a: new Map([[0, 1]]) };
const output = `{"a":[4,[[1,[[0,0],[0,1]]]]]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes a Set', () => {
const input = { a: new Set([0, 1, 2, 3]) };
const output = `{"a":[5,[[0,0],[0,1],[0,2],[0,3]]]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes a BigInt', () => {
const input = { a: BigInt('1') };
const output = `{"a":[6,"1"]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes a URL', () => {
const input = { a: new URL('https://example.com/') };
const output = `{"a":[7,"https://example.com/"]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes a Uint8Array', () => {
const input = { a: new Uint8Array([1, 2, 3]) };
const output = `{"a":[8,[1,2,3]]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes a Uint16Array', () => {
const input = { a: new Uint16Array([1, 2, 3]) };
const output = `{"a":[9,[1,2,3]]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('serializes a Uint32Array', () => {
const input = { a: new Uint32Array([1, 2, 3]) };
const output = `{"a":[10,[1,2,3]]}`;
expect(serializeProps(input)).to.equal(output);
assert.equal(serializeProps(input), output);
});
it('cannot serialize a cyclic reference', () => {
const a = {};
a.b = a;
const input = { a };
expect(() => serializeProps(input)).to.throw(/cyclic/);
assert.throws(() => serializeProps(input), { message: /cyclic/ });
});
it('cannot serialize a cyclic array', () => {
const input = { foo: ['bar'] };
input.foo.push(input);
expect(() => serializeProps(input)).to.throw(/cyclic/);
assert.throws(() => serializeProps(input), { message: /cyclic/ });
});
it('cannot serialize a deep cyclic reference', () => {
const a = { b: {} };
a.b.c = a;
const input = { a };
expect(() => serializeProps(input)).to.throw(/cyclic/);
assert.throws(() => serializeProps(input), { message: /cyclic/ });
});
it('can serialize shared references that are not cyclic', () => {
const b = {};
const input = { a: { b, b }, b };
expect(() => serializeProps(input)).not.to.throw();
assert.doesNotThrow(() => serializeProps(input));
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { before, describe, it, after } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

Expand Down Expand Up @@ -29,17 +30,17 @@ describe('set:html', () => {

it('can take a fetch()', async () => {
let res = await fixture.fetch('/fetch');
expect(res.status).to.equal(200);
assert.equal(res.status, 200);
let html = await res.text();
const $ = cheerio.load(html);
expect($('#fetched-html')).to.have.a.lengthOf(1);
expect($('#fetched-html').text()).to.equal('works');
assert.equal($('#fetched-html').length, 1);
assert.equal($('#fetched-html').text(), 'works');
});
it('test Fragment when Fragment is as a slot', async () => {
let res = await fixture.fetch('/children');
expect(res.status).to.equal(200);
assert.equal(res.status, 200);
let html = await res.text();
expect(html).include('Test');
assert.equal(html.includes('Test'), true);
});
});

Expand All @@ -51,42 +52,42 @@ describe('set:html', () => {
it('can take a string of HTML', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#html-inner')).to.have.a.lengthOf(1);
assert.equal($('#html-inner').length, 1);
});

it('can take a Promise to a string of HTML', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#promise-html-inner')).to.have.a.lengthOf(1);
assert.equal($('#promise-html-inner').length, 1);
});

it('can take a Response to a string of HTML', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#response-html-inner')).to.have.a.lengthOf(1);
assert.equal($('#response-html-inner').length, 1);
});

it('can take an Iterator', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#iterator-num')).to.have.a.lengthOf(5);
assert.equal($('#iterator-num').length, 5);
});

it('Can take an AsyncIterator', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#asynciterator-num')).to.have.a.lengthOf(5);
assert.equal($('#asynciterator-num').length, 5);
});

it('Can take a ReadableStream', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#readable-inner')).to.have.a.lengthOf(1);
assert.equal($('#readable-inner').length, 1);
});

it('test Fragment when Fragment is as a slot', async () => {
let res = await fixture.readFile('/children/index.html');
expect(res).include('Test');
assert.equal(res.includes('Test'), true);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

Expand All @@ -14,43 +15,43 @@ describe('Slots: Preact', () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);

expect($('#default-self-closing').text().trim()).to.equal('Fallback');
expect($('#default-empty').text().trim()).to.equal('Fallback');
expect($('#zero').text().trim()).to.equal('0');
expect($('#false').text().trim()).to.equal('');
expect($('#string').text().trim()).to.equal('');
expect($('#content').text().trim()).to.equal('Hello world!');
assert.equal($('#default-self-closing').text().trim(), 'Fallback');
assert.equal($('#default-empty').text().trim(), 'Fallback');
assert.equal($('#zero').text().trim(), '0');
assert.equal($('#false').text().trim(), '');
assert.equal($('#string').text().trim(), '');
assert.equal($('#content').text().trim(), 'Hello world!');
});

it('Renders named slot', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#named').text().trim()).to.equal('Fallback / Named');
assert.equal($('#named').text().trim(), 'Fallback / Named');
});

it('Converts dash-case slot to camelCase', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#dash-case').text().trim()).to.equal('Fallback / Dash Case');
assert.equal($('#dash-case').text().trim(), 'Fallback / Dash Case');
});

describe('For MDX Pages', () => {
it('Renders default slot', async () => {
const html = await fixture.readFile('/mdx/index.html');
const $ = cheerio.load(html);
expect($('#content').text().trim()).to.equal('Hello world!');
assert.equal($('#content').text().trim(), 'Hello world!');
});

it('Renders named slot', async () => {
const html = await fixture.readFile('/mdx/index.html');
const $ = cheerio.load(html);
expect($('#named').text().trim()).to.equal('Fallback / Named');
assert.equal($('#named').text().trim(), 'Fallback / Named');
});

it('Converts dash-case slot to camelCase', async () => {
const html = await fixture.readFile('/mdx/index.html');
const $ = cheerio.load(html);
expect($('#dash-case').text().trim()).to.equal('Fallback / Dash Case');
assert.equal($('#dash-case').text().trim(), 'Fallback / Dash Case');
});
});
});
Loading

0 comments on commit ef080d5

Please sign in to comment.