Skip to content

Commit

Permalink
Build and upload coverage (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
elchininet authored Dec 18, 2023
1 parent e92dadd commit fe12de6
Show file tree
Hide file tree
Showing 9 changed files with 1,051 additions and 29 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ jobs:
touch .env
echo HA_TOKEN=${{ secrets.HA_TOKEN }} >> .env
yarn test:all
- name: Create coverage
run: yarn coverage:report
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Changelog
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v3
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ jobs:
touch .env
echo HA_TOKEN=${{ secrets.HA_TOKEN }} >> .env
yarn test:all
- name: Create coverage
run: yarn coverage:report
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@v3
if: always()
with:
name: test-report
path: playwright-report/
path: |
playwright-report/
coverage/
retention-days: 30
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/node_modules
/dist
/.nyc_output
/coverage
.DS_Store
.hass/config/www/keep-texts-in-tabs.js
/test-results/
Expand Down
1 change: 0 additions & 1 deletion .hass/config/www/kiosk-mode.js

This file was deleted.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"start:ha": "docker run --rm -d -p8123:8123 --shm-size=512m -v ${PWD}/.hass/config:/config homeassistant/home-assistant:2023.11.1",
"stop:ha": "docker stop $(docker ps -a -q --filter ancestor=homeassistant/home-assistant:2023.11.1) || true",
"demo": "yarn build && yarn start:ha",
"start:playwright": "docker run --rm --network host --add-host host.docker.internal:host-gateway -v $(pwd):/work/ -w /work -i mcr.microsoft.com/playwright:v1.40.0-jammy sh -c \"yarn install --frozen-lockfile && yarn test:run && exit\"",
"start:playwright": "docker run --rm --network host --add-host host.docker.internal:host-gateway -v $(pwd):/$(pwd)/ -w $(pwd) -i mcr.microsoft.com/playwright:v1.40.0-jammy sh -c \"yarn install --frozen-lockfile && yarn test:run && exit\"",
"coverage:report": "nyc report --reporter=lcov --reporter=text-summary",
"prepare": "yarn build",
"prepublishOnly": "yarn test:all",
"version": "git add .",
Expand All @@ -29,7 +30,9 @@
"@rollup/plugin-node-resolve": "^15.2.3",
"@types/node": "^20.10.1",
"dotenv-cli": "^7.3.0",
"nyc": "^15.1.0",
"rollup": "^3.28.1",
"rollup-plugin-istanbul": "^5.0.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-ts": "^3.4.4",
"typescript": "^5.2.2"
Expand Down
59 changes: 39 additions & 20 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,48 @@ import ts from 'rollup-plugin-ts';
import json from '@rollup/plugin-json';
import { terser } from 'rollup-plugin-terser';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import istanbul from 'rollup-plugin-istanbul';

export default {
plugins: [
nodeResolve(),
json(),
ts({
browserslist: false
}),
terser({
output: {
comments: false
}
})
],
input: 'src/keep-texts-in-tabs.ts',
output: [
{
export default [
{
plugins: [
nodeResolve(),
json(),
ts({
browserslist: false
}),
terser({
output: {
comments: false
}
})
],
input: 'src/keep-texts-in-tabs.ts',
output: {
file: 'dist/keep-texts-in-tabs.js',
format: 'iife'
},
{
}
},
{
plugins: [
nodeResolve(),
json({
preferConst: true
}),
ts({
browserslist: false
}),
istanbul({
exclude: [
'node_modules/**/*',
'package.json'
]
}),
],
input: 'src/keep-texts-in-tabs.ts',
output: {
file: '.hass/config/www/keep-texts-in-tabs.js',
format: 'iife'
}
]
};
}
];
31 changes: 31 additions & 0 deletions tests/baseFixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as fs from 'fs';
import * as path from 'path';
import * as crypto from 'crypto';
import { test as baseTest } from '@playwright/test';

const istanbulCLIOutput = path.join(process.cwd(), '.nyc_output');

export function generateUUID(): string {
return crypto.randomBytes(16).toString('hex');
}

export const test = baseTest.extend({
context: async ({ context }, use) => {
await context.addInitScript(() =>
window.addEventListener('beforeunload', () =>
(window as any).collectIstanbulCoverage(JSON.stringify((window as any).__coverage__))
),
);
await fs.promises.mkdir(istanbulCLIOutput, { recursive: true });
await context.exposeFunction('collectIstanbulCoverage', (coverageJSON: string) => {
if (coverageJSON)
fs.writeFileSync(path.join(istanbulCLIOutput, `playwright_coverage_${generateUUID()}.json`), coverageJSON);
});
await use(context);
for (const page of context.pages()) {
await page.evaluate(() => (window as any).collectIstanbulCoverage(JSON.stringify((window as any).__coverage__)))
}
}
});

export const expect = test.expect;
2 changes: 1 addition & 1 deletion tests/main-options.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from '@playwright/test';
import { test, expect } from './baseFixtures';

const BASE_PAGE = 'http://host.docker.internal:8123';
const HEADER_SELECTOR = '.header ha-tabs paper-tab:last-of-type';
Expand Down
Loading

0 comments on commit fe12de6

Please sign in to comment.