Skip to content

Commit 230b4b6

Browse files
committed
MOBILE-4254 behat: Configure snapshot tests
1 parent 24cfb83 commit 230b4b6

File tree

7 files changed

+42
-14
lines changed

7 files changed

+42
-14
lines changed

.github/workflows/acceptance.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
git clone --branch master --depth 1 https://github.com/moodlehq/moodle-docker $GITHUB_WORKSPACE/moodle-docker
4343
- name: Install npm packages
4444
run: npm ci --no-audit
45+
- name: Install Behat Snapshots plugin
46+
run: git clone --branch main --depth 1 https://github.com/NoelDeMartin/moodle-local_behatsnapshots $GITHUB_WORKSPACE/moodle/local/behatsnapshots
4547
- name: Generate Behat tests plugin
4648
run: |
4749
export MOODLE_DOCKER_WWWROOT=$GITHUB_WORKSPACE/moodle
@@ -52,10 +54,18 @@ jobs:
5254
cp $GITHUB_WORKSPACE/moodle-docker/config.docker-template.php $GITHUB_WORKSPACE/moodle/config.php
5355
sed -i "61i\$CFG->behat_increasetimeout = 2;" $GITHUB_WORKSPACE/moodle/config.php
5456
sed -i "61i\$CFG->behat_ionic_wwwroot = 'http://moodleapp';" $GITHUB_WORKSPACE/moodle/config.php
57+
sed -i "61i\$CFG->behat_snapshots_path = '/var/www/html/local/moodleappbehat/tests/behat/snapshots';" $GITHUB_WORKSPACE/moodle/config.php
5558
echo "define('TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER', 'http://bbbmockserver/hash' . sha1(\$CFG->behat_wwwroot));" >> $GITHUB_WORKSPACE/moodle/config.php
5659
$GITHUB_WORKSPACE/moodle-docker/bin/moodle-docker-compose pull
5760
$GITHUB_WORKSPACE/moodle-docker/bin/moodle-docker-compose up -d
5861
$GITHUB_WORKSPACE/moodle-docker/bin/moodle-docker-wait-for-db
62+
- name: Install Imagick PHP extension
63+
run: |
64+
export MOODLE_DOCKER_WWWROOT=$GITHUB_WORKSPACE/moodle
65+
./moodle-docker/bin/moodle-docker-compose exec webserver apt-get update
66+
./moodle-docker/bin/moodle-docker-compose exec webserver apt-get install -y libmagickwand-dev --no-install-recommends
67+
./moodle-docker/bin/moodle-docker-compose exec webserver pecl install imagick
68+
./moodle-docker/bin/moodle-docker-compose exec webserver docker-php-ext-enable imagick
5969
- name: Compile & launch app with Docker
6070
run: |
6171
docker build --build-arg build_command="npm run build:test" -t moodlehq/moodleapp:behat .
@@ -65,8 +75,14 @@ jobs:
6575
- name: Init Behat
6676
run: |
6777
export MOODLE_DOCKER_WWWROOT=$GITHUB_WORKSPACE/moodle
68-
$GITHUB_WORKSPACE/moodle-docker/bin/moodle-docker-compose exec -T webserver sh -c "php admin/tool/behat/cli/init.php --parallel=8 --optimize-runs='@app&&$BEHAT_TAGS'"
78+
$GITHUB_WORKSPACE/moodle-docker/bin/moodle-docker-compose exec -T webserver sh -c "php admin/tool/behat/cli/init.php --parallel=8 --optimize-runs='@app&&~@local&&$BEHAT_TAGS'"
6979
- name: Run Behat tests
7080
run: |
7181
export MOODLE_DOCKER_WWWROOT=$GITHUB_WORKSPACE/moodle
72-
$GITHUB_WORKSPACE/moodle-docker/bin/moodle-docker-compose exec -T webserver sh -c "php admin/tool/behat/cli/run.php --verbose --tags='@app&&$BEHAT_TAGS' --auto-rerun=3"
82+
$GITHUB_WORKSPACE/moodle-docker/bin/moodle-docker-compose exec -T webserver sh -c "php admin/tool/behat/cli/run.php --verbose --tags='@app&&~@local&&$BEHAT_TAGS' --auto-rerun=3"
83+
- name: Upload Snapshot failures
84+
uses: actions/upload-artifact@v3
85+
if: ${{ failure() }}
86+
with:
87+
name: snapshot_failures
88+
path: moodle/local/moodleappbehat/tests/behat/snapshots/failures/*

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ gulp.task('watch', () => {
7171
});
7272

7373
gulp.task('watch-behat', () => {
74-
gulp.watch(['./src/**/*.feature', './local_moodleappbehat'], { interval: 500 }, gulp.parallel('behat'));
74+
gulp.watch(['./src/**/*.feature', './src/**/*.png', './local_moodleappbehat'], { interval: 500 }, gulp.parallel('behat'));
7575
});

local_moodleappbehat/tests/behat/snapshots/failures/.gitkeep

Whitespace-only changes.

scripts/build-behat-plugin.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,46 @@ async function main() {
7676
};
7777
writeFileSync(pluginFilePath, replaceArguments(fileContents, replacements));
7878

79-
// Copy feature files.
79+
// Copy feature and snapshot files.
8080
if (!excludeFeatures) {
8181
const behatTempFeaturesPath = `${pluginPath}/behat-tmp`;
82-
copySync(projectPath('src'), behatTempFeaturesPath, { filter: isFeatureFileOrDirectory });
82+
copySync(projectPath('src'), behatTempFeaturesPath, { filter: shouldCopyFileOrDirectory });
8383

8484
const behatFeaturesPath = `${pluginPath}/tests/behat`;
8585
if (!existsSync(behatFeaturesPath)) {
8686
mkdirSync(behatFeaturesPath, {recursive: true});
8787
}
8888

89-
for await (const featureFile of getDirectoryFiles(behatTempFeaturesPath)) {
90-
const featurePath = dirname(featureFile);
91-
if (!featurePath.endsWith('/tests/behat')) {
89+
for await (const file of getDirectoryFiles(behatTempFeaturesPath)) {
90+
const filePath = dirname(file);
91+
92+
if (filePath.endsWith('/tests/behat/snapshots')) {
93+
renameSync(file, behatFeaturesPath + '/snapshots/' + basename(file));
94+
95+
continue;
96+
}
97+
98+
if (!filePath.endsWith('/tests/behat')) {
9299
continue;
93100
}
94101

95-
const newPath = featurePath.substring(0, featurePath.length - ('/tests/behat'.length));
102+
const newPath = filePath.substring(0, filePath.length - ('/tests/behat'.length));
96103
const searchRegExp = /\//g;
97104
const prefix = relative(behatTempFeaturesPath, newPath).replace(searchRegExp,'-') || 'core';
98-
const featureFilename = prefix + '-' + basename(featureFile);
99-
renameSync(featureFile, behatFeaturesPath + '/' + featureFilename);
105+
const featureFilename = prefix + '-' + basename(file);
106+
renameSync(file, behatFeaturesPath + '/' + featureFilename);
100107
}
101108

102109
rmSync(behatTempFeaturesPath, {recursive: true});
103110
}
104111
}
105112

106-
function isFeatureFileOrDirectory(src) {
107-
const stats = statSync(src);
113+
function shouldCopyFileOrDirectory(path) {
114+
const stats = statSync(path);
108115

109-
return stats.isDirectory() || extname(src) === '.feature';
116+
return stats.isDirectory()
117+
|| extname(path) === '.feature'
118+
|| extname(path) === '.png';
110119
}
111120

112121
function isExcluded(file, exclusions) {

src/core/features/login/tests/behat/basic_usage.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ Feature: Test basic usage of login in app
3030
And I set the field "Your site" to "$WWWROOT" in the app
3131
And I press "Connect to your site" in the app
3232
Then I should find "Acceptance test site" in the app
33+
And I replace "/.*/" within ".core-siteurl" with "https://campus.example.edu"
34+
And the UI should match the snapshot
3335

3436
When I set the following fields to these values in the app:
3537
| Username | student1 |
3638
| Password | student1 |
3739
And I press "Log in" near "Forgotten your username or password?" in the app
3840
Then I should find "Acceptance test site" in the app
41+
And the UI should match the snapshot
3942
But I should not find "Log in" in the app
4043

4144
Scenario: Add a non existing account
Loading
Loading

0 commit comments

Comments
 (0)