Skip to content

Commit

Permalink
Merge pull request #574 from shiguredo/feature/fix-npm-pkg-e2e-test
Browse files Browse the repository at this point in the history
Feature/fix npm pkg e2e test
  • Loading branch information
voluntas authored Nov 29, 2024
2 parents f6f5da1 + 824c454 commit 3807c55
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/npm-pkg-e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ on:
- feature/*
paths:
- .github/workflows/npm-pkg-e2e-test.yml
- tests/**
schedule:
# UTC 時間で毎日 2:00 (JST で 11:00) に実行、月曜日から金曜日
- cron: "0 2 * * 1-5"

jobs:
npm-pkg-e2e-test:
timeout-minutes: 20
continue-on-error: true
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
6 changes: 2 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@

## develop


### misc

- [CHANGE] canary リリース方法を `canary.py` に変更する
- `release_canary.sh` は削除
- @voluntas

### misc

- [FIX] パッケージの E2E テストを修正する
- @voluntas
- [UPDATE] パッケージ E2E テストに 2024.2.2 / 2024.2.0 / 2021.1.7 を追加する
- @voluntas

Expand Down
1 change: 1 addition & 0 deletions examples/messaging/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<div class="container">
<h1>DataChannel messaging test</h1>
<p>複数のブラウザで開いて sendMessage することで動作確認できます</p>
<h2>sora-js-sdk version: <span id="sora-js-sdk-version"></span></h2>
<label for="channel-name">チャンネル名:</label>
<input type="text" id="channel-name" name="channel-name" value="messaging"><br>
<div id="connection-id"></div>
Expand Down
6 changes: 6 additions & 0 deletions examples/messaging/main.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ document.addEventListener('DOMContentLoaded', async () => {
const SORA_CHANNEL_ID_SUFFIX = import.meta.env.VITE_SORA_CHANNEL_ID_SUFFIX || ''
const ACCESS_TOKEN = import.meta.env.VITE_ACCESS_TOKEN || ''

const soraJsSdkVersion = Sora.version()
const soraJsSdkVersionElement = document.getElementById('sora-js-sdk-version')
if (soraJsSdkVersionElement) {
soraJsSdkVersionElement.textContent = soraJsSdkVersion
}

let client: SoraClient

document.querySelector('#connect')?.addEventListener('click', async () => {
Expand Down
13 changes: 13 additions & 0 deletions tests/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// バージョン比較用のヘルパー関数を追加
export const isVersionGreaterThanOrEqual = (packageVersion: string, version: string): boolean => {
const v1Parts = packageVersion.split('.').map(Number)
const v2Parts = version.split('.').map(Number)

for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
const v1 = v1Parts[i] || 0
const v2 = v2Parts[i] || 0
if (v1 > v2) return true
if (v1 < v2) return false
}
return true
}
13 changes: 13 additions & 0 deletions tests/message_header.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, test } from '@playwright/test'
import { isVersionGreaterThanOrEqual } from './helper'

test('messaging pages with header', async ({ browser }) => {
// 新しいページを2つ作成
Expand All @@ -9,6 +10,18 @@ test('messaging pages with header', async ({ browser }) => {
await page1.goto('http://localhost:9000/messaging/')
await page2.goto('http://localhost:9000/messaging/')

// sora js sdk のバージョンを取得する
await page1.waitForSelector('#sora-js-sdk-version')
const page1SoraJsSdkVersion = await page1.$eval('#sora-js-sdk-version', (el) => el.textContent)
if (page1SoraJsSdkVersion === null) {
throw new Error('page1SoraJsSdkVersion is null')
}
// sora-js-sdk のバージョンが 2024.2.0 以上であるか確認して、2024.2.0 未満の場合はテストをスキップする
test.skip(
!isVersionGreaterThanOrEqual(page1SoraJsSdkVersion, '2024.2.0'),
'sora-js-sdk のバージョンが 2024.2.0 以上である必要があります',
)

// チャネル名を設定する
await page1.fill('input[name="channel-name"]', 'message-header')
await page2.fill('input[name="channel-name"]', 'message-header')
Expand Down
11 changes: 11 additions & 0 deletions tests/messaging.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { expect, test } from '@playwright/test'
import { isVersionGreaterThanOrEqual } from './helper'

// sora-js-sdk のバージョンが 2024.2.0 以降の場合のみ実行したい
test('messaging pages', async ({ browser }) => {
// 新しいページを2つ作成
const page1 = await browser.newPage()
Expand All @@ -9,6 +11,15 @@ test('messaging pages', async ({ browser }) => {
await page1.goto('http://localhost:9000/messaging/')
await page2.goto('http://localhost:9000/messaging/')

// sora js sdk のバージョンを取得する
await page1.waitForSelector('#sora-js-sdk-version')
const page1SoraJsSdkVersion = await page1.$eval('#sora-js-sdk-version', (el) => el.textContent)
if (page1SoraJsSdkVersion === null) {
throw new Error('page1SoraJsSdkVersion is null')
}
// sora-js-sdk のバージョンが 2024.2.0 以上であるか確認して、2024.2.0 未満の場合はテストをスキップする
test.skip(!isVersionGreaterThanOrEqual(page1SoraJsSdkVersion, '2024.2.0'), 'sora-js-sdk のバージョンが 2024.2.0 以上である必要があります')

// Compress のTrue/Falseをランダムで設定する
const selectedCompress1 = await page1.evaluate(() => {
const checkCompress = document.getElementById('check-compress') as HTMLInputElement
Expand Down

0 comments on commit 3807c55

Please sign in to comment.