Skip to content
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ jobs:
- name: Set up Node environment
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: '20.17.0'
node-version: '22.16.0'
- name: Install node dependencies
run: check/npm ci
- name: Check build matches the current
Expand All @@ -415,7 +415,7 @@ jobs:
- name: Set up Node environment
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: '20.17.0'
node-version: '22.16.0'
- name: Install node dependencies
run: check/npm ci
- name: Lint Typescript files
Expand All @@ -430,7 +430,7 @@ jobs:
- name: Set up Node environment
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: '20.17.0'
node-version: '22.16.0'
- name: Install node dependencies
run: check/npm ci
- name: Run unit tests
Expand All @@ -447,7 +447,7 @@ jobs:
- name: Set up Node environment
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: '20.17.0'
node-version: '22.16.0'
- name: Install node dependencies
run: check/npm ci
- name: Run coverage test
Expand Down
4 changes: 4 additions & 0 deletions cirq-web/cirq_web/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
build/
**/node_modules
**/dist
vitest.config.ts
vitest.setup.ts
vite.config.ts
vitest.e2e.config.ts
25 changes: 0 additions & 25 deletions cirq-web/cirq_web/.nycrc.json

This file was deleted.

File renamed without changes.
14 changes: 12 additions & 2 deletions cirq-web/cirq_web/dist/bloch_sphere.bundle.js

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions cirq-web/cirq_web/dist/bloch_sphere.bundle.js.LICENSE.txt

This file was deleted.

14 changes: 12 additions & 2 deletions cirq-web/cirq_web/dist/circuit.bundle.js

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions cirq-web/cirq_web/dist/circuit.bundle.js.LICENSE.txt

This file was deleted.

14 changes: 0 additions & 14 deletions cirq-web/cirq_web/dist/html/bloch_sphere.html

This file was deleted.

29 changes: 0 additions & 29 deletions cirq-web/cirq_web/dist/html/circuit.html

This file was deleted.

14 changes: 0 additions & 14 deletions cirq-web/cirq_web/dist/index.html

This file was deleted.

92 changes: 40 additions & 52 deletions cirq-web/cirq_web/e2e/bloch_sphere/bloch_sphere_e2e_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import puppeteer from 'puppeteer';
import {expect} from 'chai';
import {beforeAll, describe, it, expect} from 'vitest';
import {readFileSync} from 'fs';
import pixelmatch from 'pixelmatch';
import * as PNG from 'pngjs';
Expand Down Expand Up @@ -53,65 +53,53 @@ function htmlContent(clientCode: string) {
temp.track();

describe('Bloch sphere', () => {
// Create the temporary directory first, then run everything.
temp.mkdir('tmp', (err, dirPath) => {
const outputPath = path.join(dirPath, 'bloch_sphere');
const newVectorOutputPath = path.join(dirPath, 'bloch_sphere_vec');

before(async () => {
// Opens a headless browser with the generated HTML file and takes a screenshot.
// The '--app' flag ensures that chromium does capture any
// excess browser input
const browser = await puppeteer.launch({args: ['--app']});
const page = await browser.newPage();

// Take a screenshot of the first image
await page.setContent(htmlContent("renderBlochSphere('container')"));
await page.screenshot({path: `${outputPath}.png`});
await browser.close();
});
const dirPath = temp.mkdirSync('tmp');
const outputPath = path.join(dirPath, 'bloch_sphere');
const newVectorOutputPath = path.join(dirPath, 'bloch_sphere_vec');

beforeAll(async () => {
const browser = await puppeteer.launch({args: ['--app']});
const page = await browser.newPage();

it('with no vector matches the gold PNG', () => {
const expected = PNG.PNG.sync.read(
readFileSync('e2e/bloch_sphere/bloch_sphere_expected.png'),
);
const actual = PNG.PNG.sync.read(readFileSync(`${outputPath}.png`));
const {width, height} = expected;
const diff = new PNG.PNG({width, height});
await page.setContent(htmlContent("renderBlochSphere('container')"));
await page.screenshot({path: `${outputPath}.png`});
await browser.close();
});

const pixels = pixelmatch(expected.data, actual.data, diff.data, width, height, {
threshold: 0.1,
});
it('with no vector matches the gold PNG', () => {
const expected = PNG.PNG.sync.read(readFileSync('e2e/bloch_sphere/bloch_sphere_expected.png'));
const actual = PNG.PNG.sync.read(readFileSync(`${outputPath}.png`));
const {width, height} = expected;
const diff = new PNG.PNG({width, height});

expect(pixels).to.equal(0);
const pixels = pixelmatch(expected.data, actual.data, diff.data, width, height, {
threshold: 0.1,
});

before(async () => {
//Opens a headless browser with the generated HTML file and takes a screenshot.
const browser = await puppeteer.launch({args: ['--app']});
const page = await browser.newPage();

// Take a screenshot of the second image, adding the vector
await page.setContent(
htmlContent("renderBlochSphere('container').addVector(0.5, 0.5, 0.5);"),
);
await page.screenshot({path: `${newVectorOutputPath}.png`});
await browser.close();
});
expect(pixels).toBe(0);
});

beforeAll(async () => {
const browser = await puppeteer.launch({args: ['--app']});
const page = await browser.newPage();

it('with custom statevector matches the gold PNG', () => {
const expected = PNG.PNG.sync.read(
readFileSync('e2e/bloch_sphere/bloch_sphere_expected_custom.png'),
);
const actual = PNG.PNG.sync.read(readFileSync(`${newVectorOutputPath}.png`));
const {width, height} = expected;
const diff = new PNG.PNG({width, height});
await page.setContent(htmlContent("renderBlochSphere('container').addVector(0.5, 0.5, 0.5);"));
await page.screenshot({path: `${newVectorOutputPath}.png`});
await browser.close();
});

const pixels = pixelmatch(expected.data, actual.data, diff.data, width, height, {
threshold: 0.1,
});
it('with custom statevector matches the gold PNG', () => {
const expected = PNG.PNG.sync.read(
readFileSync('e2e/bloch_sphere/bloch_sphere_expected_custom.png'),
);
const actual = PNG.PNG.sync.read(readFileSync(`${newVectorOutputPath}.png`));
const {width, height} = expected;
const diff = new PNG.PNG({width, height});

expect(pixels).to.equal(0);
const pixels = pixelmatch(expected.data, actual.data, diff.data, width, height, {
threshold: 0.1,
});

expect(pixels).toBe(0);
});
});
44 changes: 21 additions & 23 deletions cirq-web/cirq_web/e2e/circuit/circuit_e2e_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import puppeteer from 'puppeteer';
import {expect} from 'chai';
import {beforeAll, describe, it, expect} from 'vitest';
import {readFileSync} from 'fs';
import pixelmatch from 'pixelmatch';
import * as PNG from 'pngjs';
Expand Down Expand Up @@ -49,16 +49,15 @@ function htmlContent(clientCode: string) {
temp.track();

describe('Circuit', () => {
temp.mkdir('tmp', (err, dirPath) => {
const outputPath = path.join(dirPath, 'circuit');
const dirPath = temp.mkdirSync('tmp');
const outputPath = path.join(dirPath, 'circuit');

before(async () => {
const browser = await puppeteer.launch({args: ['--app']});
const page = await browser.newPage();
beforeAll(async () => {
const browser = await puppeteer.launch({args: ['--app']});
const page = await browser.newPage();

// Take a screenshot of the first image
await page.setContent(
htmlContent(`
await page.setContent(
htmlContent(`
const circuit = createGridCircuit(
[
{
Expand All @@ -82,22 +81,21 @@ describe('Circuit', () => {
], 5, 'mycircuitdiv'
);
`),
);
await page.screenshot({path: `${outputPath}.png`});
await browser.close();
});

it('with limited gates matches the gold copy', () => {
const expected = PNG.PNG.sync.read(readFileSync('e2e/circuit/circuit_expected.png'));
const actual = PNG.PNG.sync.read(readFileSync(`${outputPath}.png`));
const {width, height} = expected;
const diff = new PNG.PNG({width, height});
);
await page.screenshot({path: `${outputPath}.png`});
await browser.close();
});

const pixels = pixelmatch(expected.data, actual.data, diff.data, width, height, {
threshold: 0.1,
});
it('with limited gates matches the gold copy', () => {
const expected = PNG.PNG.sync.read(readFileSync('e2e/circuit/circuit_expected.png'));
const actual = PNG.PNG.sync.read(readFileSync(`${outputPath}.png`));
const {width, height} = expected;
const diff = new PNG.PNG({width, height});

expect(pixels).to.equal(0);
const pixels = pixelmatch(expected.data, actual.data, diff.data, width, height, {
threshold: 0.1,
});

expect(pixels).toBe(0);
});
});
Loading