Skip to content

Commit 1d129f3

Browse files
Merge pull request #287 from rtCamp/playwright/test
Add e2e test cases for nginx-helper plugin
2 parents 9df26ee + d208965 commit 1d129f3

File tree

210 files changed

+16072
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+16072
-0
lines changed

.github/ci/main.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
######################################################
6+
######################## VARS ########################
7+
SITE_NAME='nginx-helper.com'
8+
SITE_ROOT="/var/www/$SITE_NAME/htdocs"
9+
SITE_URL="http://$SITE_NAME/"
10+
function ee() { wo "$@"; }
11+
#####################################################
12+
13+
# Start required services for site creation
14+
function start_services() {
15+
16+
echo "Starting services"
17+
git config --global user.email "nobody@example.com"
18+
git config --global user.name "nobody"
19+
rm /etc/nginx/conf.d/stub_status.conf /etc/nginx/sites-available/22222 /etc/nginx/sites-enabled/22222
20+
rm -rf /var/www/22222
21+
ee stack start --nginx --mysql --php74
22+
ee stack status --nginx --mysql --php74
23+
}
24+
25+
26+
# Create, setup and populate learn.rtcamp.com base site with data
27+
function create_and_configure_site () {
28+
29+
ee site create $SITE_NAME --wp --php74
30+
cd $SITE_ROOT/wp-content/plugins/
31+
rm -rf nginx-helper
32+
ls
33+
mkdir nginx-helper
34+
rsync -azh $GITHUB_WORKSPACE/ $SITE_ROOT/wp-content/plugins/nginx-helper
35+
echo "127.0.0.1 $SITE_NAME" >> /etc/hosts
36+
ls
37+
wp plugin activate nginx-helper --allow-root
38+
wp user create automation automation@example.com --role=administrator --user_pass=automation --allow-root
39+
wp theme activate twentytwentyone --allow-root
40+
}
41+
42+
43+
# Install WPe2e dependency
44+
function install_playwright_package () {
45+
46+
cd $GITHUB_WORKSPACE/tests/e2e-playwright
47+
npm install
48+
49+
}
50+
51+
#build packages
52+
function build_package(){
53+
cd $GITHUB_WORKSPACE/tests/e2e-playwright
54+
npm run build
55+
}
56+
57+
function install_playwright(){
58+
cd $GITHUB_WORKSPACE/tests/e2e-playwright
59+
npx playwright install
60+
}
61+
62+
# Run test for new deployed site
63+
function run_playwright_tests () {
64+
cd $GITHUB_WORKSPACE/tests/e2e-playwright
65+
npm run test-e2e:playwright -- specs/
66+
}
67+
68+
function maybe_install_node_dep() {
69+
70+
if [[ -n "$NODE_VERSION" ]]; then
71+
72+
echo "Setting up $NODE_VERSION"
73+
NVM_LATEST_VER=$(curl -s "https://api.github.com/repos/nvm-sh/nvm/releases/latest" |
74+
grep '"tag_name":' |
75+
sed -E 's/.*"([^"]+)".*/\1/') &&
76+
curl -fsSL "https://raw.githubusercontent.com/nvm-sh/nvm/$NVM_LATEST_VER/install.sh" | bash
77+
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
78+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
79+
80+
nvm install "$NODE_VERSION"
81+
nvm use "$NODE_VERSION"
82+
83+
[[ -z "$NPM_VERSION" ]] && NPM_VERSION="latest" || echo ''
84+
export npm_install=$NPM_VERSION
85+
curl -fsSL https://www.npmjs.com/install.sh | bash
86+
fi
87+
}
88+
89+
function main() {
90+
start_services
91+
create_and_configure_site
92+
maybe_install_node_dep
93+
install_playwright_package
94+
build_package
95+
install_playwright
96+
run_playwright_tests
97+
}
98+
99+
main

.github/workflows/e2e-test.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# e2e test for nginx helper plugin
2+
3+
name: CI for Login with nginx helper test
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Triggers the workflow on push or pull request events but only for the main branch
8+
push:
9+
branches:
10+
- develop
11+
- master
12+
13+
pull_request:
14+
branches:
15+
- develop
16+
- master
17+
18+
# Allows you to run this workflow manually from the Actions tab
19+
workflow_dispatch:
20+
21+
jobs:
22+
Run-wpe2e-TestCase:
23+
# The type of runner that the job will run on
24+
name: Run nginx helper plugin test Cases
25+
runs-on: ubuntu-latest
26+
27+
# Steps represent a sequence of tasks that will be executed as part of the job
28+
steps:
29+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
30+
- uses: actions/checkout@v3
31+
with:
32+
ref: ${{ github.event.pull_request.head.sha }}
33+
34+
# Check node version
35+
- name: Current directory and listings
36+
run: |
37+
pwd
38+
ls -al
39+
# Install config site
40+
- name: Install and config site
41+
uses: docker://rtcamp/base-wo:v1.0.0
42+
env:
43+
NODE_VERSION: 16
44+
RCLONE_CONFIG: ${{ secrets.RCLONE_CONFIG }}
45+
46+
- name: Archive HTML Report on failure
47+
if: failure()
48+
uses: actions/upload-artifact@v1
49+
with:
50+
name: report
51+
path: ./tests/e2e-playwright/config
52+
53+
- name: Cleanup
54+
if: ${{ always() }}
55+
uses: rtCamp/action-cleanup@master

tests/e2e-playwright/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
artifacts
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/**
2+
* External dependencies
3+
*/
4+
const { promisify } = require( 'util' );
5+
const fs = require( 'fs' );
6+
const path = require( 'path' );
7+
const babel = require( '@babel/core' );
8+
const makeDir = require( 'make-dir' );
9+
const sass = require( 'sass' );
10+
const postcss = require( 'postcss' );
11+
/**
12+
* Internal dependencies
13+
*/
14+
const getBabelConfig = require( './get-babel-config' );
15+
16+
/**
17+
* Path to packages directory.
18+
*
19+
* @type {string}
20+
*/
21+
const PACKAGES_DIR = path
22+
.resolve( __dirname, '../../packages' )
23+
.replace( /\\/g, '/' );
24+
25+
/**
26+
* Mapping of JavaScript environments to corresponding build output.
27+
*
28+
* @type {Object}
29+
*/
30+
const JS_ENVIRONMENTS = {
31+
main: 'build',
32+
module: 'build-module',
33+
};
34+
35+
/**
36+
* Promisified fs.readFile.
37+
*
38+
* @type {Function}
39+
*/
40+
const readFile = promisify( fs.readFile );
41+
42+
/**
43+
* Promisified fs.writeFile.
44+
*
45+
* @type {Function}
46+
*/
47+
const writeFile = promisify( fs.writeFile );
48+
49+
/**
50+
* Promisified sass.render.
51+
*
52+
* @type {Function}
53+
*/
54+
const renderSass = promisify( sass.render );
55+
56+
/**
57+
* Get the package name for a specified file
58+
*
59+
* @param {string} file File name.
60+
*
61+
* @return {string} Package name.
62+
*/
63+
function getPackageName( file ) {
64+
return path.relative( PACKAGES_DIR, file ).split( path.sep )[ 0 ];
65+
}
66+
67+
/**
68+
* Get Build Path for a specified file.
69+
*
70+
* @param {string} file File to build.
71+
* @param {string} buildFolder Output folder.
72+
*
73+
* @return {string} Build path.
74+
*/
75+
function getBuildPath( file, buildFolder ) {
76+
const pkgName = getPackageName( file );
77+
const pkgSrcPath = path.resolve( PACKAGES_DIR, pkgName, 'src' );
78+
const pkgBuildPath = path.resolve( PACKAGES_DIR, pkgName, buildFolder );
79+
const relativeToSrcPath = path.relative( pkgSrcPath, file );
80+
return path.resolve( pkgBuildPath, relativeToSrcPath );
81+
}
82+
83+
async function buildCSS( file ) {
84+
const outputFile = getBuildPath(
85+
file.replace( '.scss', '.css' ),
86+
'build-style'
87+
);
88+
const outputFileRTL = getBuildPath(
89+
file.replace( '.scss', '-rtl.css' ),
90+
'build-style'
91+
);
92+
93+
const [ , contents ] = await Promise.all( [
94+
makeDir( path.dirname( outputFile ) ),
95+
readFile( file, 'utf8' ),
96+
] );
97+
98+
const importLists = [
99+
'colors',
100+
'breakpoints',
101+
'variables',
102+
'mixins',
103+
'animations',
104+
'z-index',
105+
]
106+
// Editor styles should be excluded from the default CSS vars output.
107+
.concat(
108+
file.includes( 'common.scss' ) || ! file.includes( 'block-library' )
109+
? [ 'default-custom-properties' ]
110+
: []
111+
)
112+
.map( ( imported ) => `@import "${ imported }";` )
113+
.join( ' ' );
114+
115+
const builtSass = await renderSass( {
116+
file,
117+
includePaths: [ path.join( PACKAGES_DIR, 'base-styles' ) ],
118+
data: ''.concat( '@use "sass:math";', importLists, contents ),
119+
} );
120+
121+
const result = await postcss(
122+
require( '@wordpress/postcss-plugins-preset' )
123+
).process( builtSass.css, {
124+
from: 'src/app.css',
125+
to: 'dest/app.css',
126+
} );
127+
128+
const resultRTL = await postcss( [ require( 'rtlcss' )() ] ).process(
129+
result.css,
130+
{
131+
from: 'src/app.css',
132+
to: 'dest/app.css',
133+
}
134+
);
135+
136+
await Promise.all( [
137+
writeFile( outputFile, result.css ),
138+
writeFile( outputFileRTL, resultRTL.css ),
139+
] );
140+
}
141+
142+
async function buildJS( file ) {
143+
for ( const [ environment, buildDir ] of Object.entries(
144+
JS_ENVIRONMENTS
145+
) ) {
146+
const destPath = getBuildPath(
147+
file.replace( /\.tsx?$/, '.js' ),
148+
buildDir
149+
);
150+
const babelOptions = getBabelConfig(
151+
environment,
152+
file.replace( PACKAGES_DIR, '@wordpress' )
153+
);
154+
155+
const [ , transformed ] = await Promise.all( [
156+
makeDir( path.dirname( destPath ) ),
157+
babel.transformFileAsync( file, babelOptions ),
158+
] );
159+
160+
await Promise.all( [
161+
writeFile( destPath + '.map', JSON.stringify( transformed.map ) ),
162+
writeFile(
163+
destPath,
164+
transformed.code +
165+
'\n//# sourceMappingURL=' +
166+
path.basename( destPath ) +
167+
'.map'
168+
),
169+
] );
170+
}
171+
}
172+
173+
/**
174+
* Object of build tasks per file extension.
175+
*
176+
* @type {Object<string,Function>}
177+
*/
178+
const BUILD_TASK_BY_EXTENSION = {
179+
'.scss': buildCSS,
180+
'.js': buildJS,
181+
'.ts': buildJS,
182+
'.tsx': buildJS,
183+
};
184+
185+
module.exports = async ( file, callback ) => {
186+
const extension = path.extname( file );
187+
const task = BUILD_TASK_BY_EXTENSION[ extension ];
188+
189+
if ( ! task ) {
190+
callback( new Error( `No handler for extension: ${ extension }` ) );
191+
}
192+
193+
try {
194+
await task( file );
195+
callback();
196+
} catch ( error ) {
197+
callback( error );
198+
}
199+
};

0 commit comments

Comments
 (0)