Skip to content

Commit

Permalink
Merge pull request #2 from todays-mitsui/add-test
Browse files Browse the repository at this point in the history
e2eテストを追加する
  • Loading branch information
todays-mitsui authored May 31, 2024
2 parents d8a5bfc + 262174c commit d45d0d7
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 3 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- "src/**"
- "test/**"

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm ci

- name: Start wp-env local server
run: nohup npm start &

- name: Wait for local server to start
run: |
while ! nc -z localhost 8889; do
sleep 1
done
- name: Run tests
run: npm test
1 change: 1 addition & 0 deletions artifacts/storage-states/admin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cookies":[{"name":"wordpress_test_cookie","value":"WP%20Cookie%20check","domain":"localhost","path":"/","expires":-1,"httpOnly":false,"secure":false,"sameSite":"Lax"},{"name":"wordpress_23778236db82f19306f247e20a353a99","value":"admin%7C1717235962%7CrdtWoFHwA11nQRfIwVH2DblwNSkH7Rlo6j1osrLKg6o%7C6535e5ea286bbe966bbba1817959cc676401d77a4ea9280af819d86b149db65a","domain":"localhost","path":"/wp-content/plugins","expires":-1,"httpOnly":true,"secure":false,"sameSite":"Lax"},{"name":"wordpress_23778236db82f19306f247e20a353a99","value":"admin%7C1717235962%7CrdtWoFHwA11nQRfIwVH2DblwNSkH7Rlo6j1osrLKg6o%7C6535e5ea286bbe966bbba1817959cc676401d77a4ea9280af819d86b149db65a","domain":"localhost","path":"/wp-admin","expires":-1,"httpOnly":true,"secure":false,"sameSite":"Lax"},{"name":"wordpress_logged_in_23778236db82f19306f247e20a353a99","value":"admin%7C1717235962%7CrdtWoFHwA11nQRfIwVH2DblwNSkH7Rlo6j1osrLKg6o%7Cf83bc297e9c6946f38fc750f1b876981adcd4184e27b58e9e8ba87792c8fc4a2","domain":"localhost","path":"/","expires":-1,"httpOnly":true,"secure":false,"sameSite":"Lax"},{"name":"wp-settings-time-1","value":"1717063163","domain":"localhost","path":"/","expires":1748599163.075,"httpOnly":false,"secure":false,"sameSite":"Lax"}],"nonce":"68d34ccc5a","rootURL":"http://localhost:8889/index.php?rest_route=/"}
4 changes: 4 additions & 0 deletions artifacts/test-results/.last-run.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"status": "passed",
"failedTests": []
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
"stop": "wp-env stop",
"clean": "wp-env clean",
"destroy": "wp-env destroy",
"logs": "wp-env logs"
"logs": "wp-env logs",
"test": "run-s test:unit test:e2e",
"test:unit": "wp-scripts test-unit-js",
"test:e2e": "wp-scripts test-playwright",
"test:e2e:debug": "wp-scripts test-playwright --debug"
},
"devDependencies": {
"@wordpress/element": "^5.35.0",
Expand Down
10 changes: 10 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from '@playwright/test';

const baseConfig = require( '@wordpress/scripts/config/playwright.config.js' );

const config = defineConfig( {
...baseConfig,
testDir: './test/e2e',
} );

export default config;
2 changes: 1 addition & 1 deletion test/Grid.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Grid } from './src/Model/Grid';
import { Grid } from '../src/Model/Grid';

describe( 'Grid', () => {
describe( 'constructor', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:todays-mitsui/nonogram -->
<div class="wp-block-todays-mitsui-nonogram" style="aspect-ratio:1 / 1" data-aspect-ratio="1:1" data-row-clues="0;0;0;0;0;0;0;0;0;0;0;0;0;0;0" data-column-clues="0;0;0;0;0;0;0;0;0;0;0;0;0;0;0"></div>
<!-- /wp:todays-mitsui/nonogram -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:todays-mitsui/nonogram -->
<div class="wp-block-todays-mitsui-nonogram" style="aspect-ratio:1 / 1" data-aspect-ratio="1:1" data-row-clues="0;0;0;0;0;0;0;0;0;0;0;0;0;0;0" data-column-clues="0;0;0;0;0;0;0;0;0;0;0;0;0;0;0"></div>
<!-- /wp:todays-mitsui/nonogram -->
18 changes: 18 additions & 0 deletions test/e2e/addBlock.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, expect } from '@wordpress/e2e-test-utils-playwright';

test.describe( 'addBlock', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );

test( 'should add a block', async ( { editor } ) => {
await editor.insertBlock( {
name: 'todays-mitsui/nonogram',
attributes: {
aspectRatio: [ 1, 1 ],
boardData: null,
},
} );
expect( await editor.getEditedPostContent() ).toMatchSnapshot();
} );
} );
2 changes: 1 addition & 1 deletion test/util.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { encode, decode } from './src/lib/encode';
import { encode, decode } from '../src/lib/encode';

describe( 'encode/decode', () => {
test( 'should encode serials to code', () => {
Expand Down

0 comments on commit d45d0d7

Please sign in to comment.