Skip to content

Commit

Permalink
Added some simple test scaffolding (#7066)
Browse files Browse the repository at this point in the history
# Pull Request

## πŸ“– Description

This adds a simple binding, per #7037 to facilitate playwright testing.

## πŸ‘©β€πŸ’» Reviewer Notes

This is some simple scaffolding, no code we intend to ship is in here but this will make future PRs cleaner as they won't include unrelated changes.

## βœ… Checklist

### General

<!--- Review the list and put an x in the boxes that apply. -->

- [ ] I have included a change request file using `$ npm run change`
- [ ] I have added tests for my changes.
- [x] I have tested my changes.
- [x] I have updated the project documentation to reflect my changes.
- [x] I have read the [CONTRIBUTING](https://github.com/microsoft/fast/blob/main/CONTRIBUTING.md) documentation and followed the [standards](https://github.com/microsoft/fast/blob/main/CODE_OF_CONDUCT.md#our-standards) for this project.
  • Loading branch information
janechu authored Jan 27, 2025
1 parent 93f3962 commit b92c7af
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 43 deletions.
9 changes: 6 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions packages/web-components/fast-btr/docs/api-report.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## API Report File for "@microsoft/fast-btr"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts

// (No @packageDocumentation comment for this package)

```
81 changes: 41 additions & 40 deletions packages/web-components/fast-btr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,62 @@
"private": true,
"type": "module",
"author": {
"name": "Microsoft",
"url": "https://discord.gg/FcSNfg4"
"name": "Microsoft",
"url": "https://discord.gg/FcSNfg4"
},
"homepage": "https://www.fast.design/",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/Microsoft/fast.git",
"directory": "packages/web-components/fast-btr"
"type": "git",
"url": "git+https://github.com/Microsoft/fast.git",
"directory": "packages/web-components/fast-btr"
},
"bugs": {
"url": "https://github.com/Microsoft/fast/issues/new/choose"
"url": "https://github.com/Microsoft/fast/issues/new/choose"
},
"scripts": {
"clean": "tsc -b --clean src",
"build": "tsc -b src && npm run doc",
"doc": "api-extractor run --local",
"doc:ci": "api-extractor run",
"prepublishOnly": "npm run clean && npm run build",
"build-server": "tsc -b server",
"eslint": "eslint . --ext .ts",
"eslint:fix": "eslint . --ext .ts --fix",
"pretest": "npm run build-server && npm run build",
"prettier:diff": "prettier --config ../../../.prettierrc \"**/*.{ts,html}\" --list-different",
"prettier": "prettier --config ../../../.prettierrc --write \"**/*.{ts,html}\"",
"test": "playwright test --config=playwright.config.cjs",
"test-server": "node server/dist/server.js",
"install-playwright-browsers": "npm run playwright install"
"clean": "tsc -b --clean src",
"clean:dist": "node ../../../build/clean.js dist",
"build": "tsc -b src && npm run doc",
"doc": "api-extractor run --local",
"doc:ci": "api-extractor run",
"prepublishOnly": "npm run clean && npm run build",
"build-server": "tsc -b server",
"eslint": "eslint . --ext .ts",
"eslint:fix": "eslint . --ext .ts --fix",
"pretest": "npm run build-server && npm run build",
"prettier:diff": "prettier --config ../../../.prettierrc \"**/*.{ts,html}\" --list-different",
"prettier": "prettier --config ../../../.prettierrc --write \"**/*.{ts,html}\"",
"test": "playwright test --config=playwright.config.cjs",
"test-server": "node server/dist/server.js",
"install-playwright-browsers": "npm run playwright install"
},
"description": "A package for facilitating rendering FAST Web Components in a non-browser environment.",
"exports": {
".": {
"types": "./dist/dts/index.d.ts",
"default": "./dist/esm/index.js"
},
"./package.json": "./package.json"
".": {
"types": "./dist/dts/index.d.ts",
"default": "./dist/esm/index.js"
},
"./package.json": "./package.json"
},
"peerDependencies": {
"@microsoft/fast-element": "^2.0.1"
"@microsoft/fast-element": "^2.0.1"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.47.0",
"@microsoft/fast-element": "^2.0.1",
"@playwright/test": "^1.49.0",
"@types/express": "^4.17.21",
"@types/node": "^17.0.17",
"express": "^4.19.2",
"typescript": "~5.3.0"
"@microsoft/api-extractor": "^7.47.0",
"@microsoft/fast-element": "^2.0.1",
"@playwright/test": "^1.49.0",
"@types/express": "^4.17.21",
"@types/node": "^17.0.17",
"express": "^4.19.2",
"typescript": "~5.3.0"
},
"beachball": {
"disallowedChangeTypes": [
"major",
"minor",
"patch"
],
"tag": "alpha"
"disallowedChangeTypes": [
"major",
"minor",
"patch"
],
"tag": "alpha"
}
}
}
2 changes: 2 additions & 0 deletions packages/web-components/fast-btr/server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Server
This project contains the web server that playwright tests are run against. To build, run `npm run build-server`.
37 changes: 37 additions & 0 deletions packages/web-components/fast-btr/server/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import fs from "fs";
import path from "path";
import { Readable } from "stream";

import express, { Request, Response } from "express";

const __dirname = path.resolve(path.dirname(""));
const PORT = 8080;

function handlePathRequest(
mapPath: string,
contentType: string,
req: Request,
res: Response
) {
res.set("Content-Type", contentType);
fs.readFile(path.resolve(__dirname, mapPath), { encoding: "utf8" }, (err, data) => {
const stream = (Readable as any).from(data);

stream.on("readable", function (this: any) {
while ((data = this.read())) {
res.write(data);
}
});
stream.on("close", () => res.end());
stream.on("error", (e: Error) => {
console.error(e);
process.exit(1);
});
});
}

const app = express();
app.get("/binding", (req: Request, res: Response) =>
handlePathRequest("./src/fixtures/binding.fixture.html", "text/html", req, res)
);
app.listen(PORT);
9 changes: 9 additions & 0 deletions packages/web-components/fast-btr/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"composite": true,
"rootDir": ".",
"outDir": "dist"
},
"references": [{ "path": "../src"}]
}
19 changes: 19 additions & 0 deletions packages/web-components/fast-btr/src/fixtures/binding.fixture.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<custom-element text="Hello world">
<template shadowrootmode="open">
Hello world
</template>
</custom-element>
<f-template name="custom-element">
<template>
{{text}}
</template>
</f-template>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"text": "Hello world"
}
6 changes: 6 additions & 0 deletions packages/web-components/fast-btr/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expect, test } from "@playwright/test";

test("placeholder", async () => {
// TODO: update this with tests against fixtures
expect(1+1).toEqual(2);
});
13 changes: 13 additions & 0 deletions packages/web-components/fast-btr/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"composite": true,
"rootDir": ".",
"outDir": "../dist/esm",
"declarationDir": "../dist/dts",
"lib": [
"dom",
"esnext"
],
},
}

0 comments on commit b92c7af

Please sign in to comment.