How can I add fixtures for testing Strapi project with jest.
and is there a way to add such testing data in Strapi, like fixtures in ruby on rails?
this is an example of rubyOnRail fixtures:
# lo & behold! I am a YAML comment!
david:
name: David Heinemeier Hansson
birthday: 1979-10-15
profession: Systems development
steve:
name: Steve Ross Kellock
birthday: 1974-09-27
profession: guy with keyboard
strapi-plugin-import-export-content has been updated for Strapi4 but requires some work to inject exported data to its apis (Authentication mainly). Also, single types have no export/import buttons by default so I don't know if the import/export apis work with them.
For now, the easiest workaround I found is to set a dedicated sqlite db for tests with seed data.
!!! Beware of the credentials of your super admin account if you do that, DO NOT PUSH TRUE CREDENTIALS ONLINE, they could remain in old commits for ever !!!
Here are some scripts I use to export/import fixtures:
#!/usr/bin/env bash
# tests/export_sqlite_fixtures.sh
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
sqlite3 "$SCRIPT_DIR/../.tmp/data.db" ".output $SCRIPT_DIR/fixtures.sql.dump" ".dump"
#!/usr/bin/env bash
# tests/import_sqlite_fixtures.sh
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
sqlite3 "$SCRIPT_DIR/../.tmp/data.db" ".output $SCRIPT_DIR/fixtures.sql.dump" ".dump"
Then in my CI pipe i just add (Github action here):
- name: Populate sqlite db with fixtures
run: ./tests/import_sqlite_fixtures.sh
- name: build Strapi
run: yarn build
...
NB: The extension of the export is .sql.dump to keep the *.sql rule in the .gitignore
Related
I'm trying to set up an AWS CodeBuild project to run tests to validate PRs and commits on a GitHub repository.
Because of the nature of the repo (a monorepo combining several ML models):
I need to restrict down to only run tests associated with files changed in the PR/commit to keep time+cost under control, but
The tests will typically require reference to other un-changed files in the repo: So can't just only pull changed files through to the build container.
How can a running CodeBuild build triggered by a GitHub PR (as per the docs here) 'see' which files are changed by the PR to selectively execute tests?
In your buildspec file you can perform shell commands, I think you can use some git commands there and echo the result, so you can see them as logs during the build.
You can use git diff --name-only $$CODEBUILD_RESOLVED_SOURCE_VERSION $$CODEBUILD_WEBHOOK_PREV_COMMIT
Where $CODEBUILD_WEBHOOK_PREV_COMMIT is the commit id of the previous commit. And $CODEBUILD_RESOLVED_SOURCE_VERSION is the commit id of the actual one.
Inside a build phase you can check the change with:
- |
if [ "$(git diff --name-only $CODEBUILD_RESOLVED_SOURCE_VERSION $CODEBUILD_WEBHOOK_PREV_COMMIT | grep -e <filde_path>)" != "" ]; then
#your code;
fi
In yaml file below we are running with next command: java org.testng.TestNG testng.xml.
Is it possible to run tests something like this ./gradlew clean runTests testng.xml?
**version: 0.1
# Phases are collection of commands that get executed on Device Farm.
phases:
# The install phase includes commands that install dependencies that your tests use.
# Default dependencies for testing frameworks supported on Device Farm are already installed.
install:
commands:
# This test execution environment uses Appium version 1.9.1 by default, however we enable you to change it using the Appium version manager (avm). An
# example "avm" command below changes the version to 1.14.2.
# For your convenience, we have preinstalled the following versions: 1.9.1, 1.10.1, 1.11.1, 1.12.1, 1.13.0, 1.14.1, 1.14.2, 1.15.1 or 1.16.0.
# To use one of these Appium versions, change the version number in the "avm" command below to your desired version:
- export APPIUM_VERSION=1.14.2
- avm $APPIUM_VERSION
- ln -s /usr/local/avm/versions/$APPIUM_VERSION/node_modules/.bin/appium /usr/local/avm/versions/$APPIUM_VERSION/node_modules/appium/bin/appium.js
# The pre-test phase includes commands that setup your test environment.
pre_test:
commands:
# Setup environment variables for java
- export CLASSPATH=$CLASSPATH:$DEVICEFARM_TESTNG_JAR
- export CLASSPATH=$CLASSPATH:$DEVICEFARM_TEST_PACKAGE_PATH/*
- export CLASSPATH=$CLASSPATH:$DEVICEFARM_TEST_PACKAGE_PATH/dependency-jars/*
# We recommend starting appium server process in the background using the command below.
# Appium server log will go to $DEVICEFARM_LOG_DIR directory.
# The environment variables below will be auto-populated during run time.
- echo "Start appium server"
- >-
appium --log-timestamp
--default-capabilities "{\"deviceName\": \"$DEVICEFARM_DEVICE_NAME\", \"platformName\":\"$DEVICEFARM_DEVICE_PLATFORM_NAME\",
\"app\":\"$DEVICEFARM_APP_PATH\", \"udid\":\"$DEVICEFARM_DEVICE_UDID\", \"platformVersion\":\"$DEVICEFARM_DEVICE_OS_VERSION\",
\"chromedriverExecutable\":\"$DEVICEFARM_CHROMEDRIVER_EXECUTABLE\"}"
>> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 &
- >-
start_appium_timeout=0;
while [ true ];
do
if [ $start_appium_timeout -gt 60 ];
then
echo "appium server never started in 60 seconds. Exiting";
exit 1;
fi;
grep -i "Appium REST http interface listener started on 0.0.0.0:4723" $DEVICEFARM_LOG_DIR/appiumlog.txt >> /dev/null 2>&1;
if [ $? -eq 0 ];
then
echo "Appium REST http interface listener started on 0.0.0.0:4723";
break;
else
echo "Waiting for appium server to start. Sleeping for 1 second";
sleep 1;
start_appium_timeout=$((start_appium_timeout+1));
fi;
done;
# The test phase includes commands that start your test suite execution.
test:
commands:
# Your test package is downloaded in $DEVICEFARM_TEST_PACKAGE_PATH so we first change directory to that path.
- echo "Navigate to test package directory"
- echo $DEVICEFARM_TEST_PACKAGE_PATH
- cd $DEVICEFARM_TEST_PACKAGE_PATH
# By default, the following command is used by Device Farm to run your Appium TestNG test.
# The goal is to run to your tests jar file with all the dependencies jars in the CLASSPATH.
# Alternatively, You may specify your customized command.
# Note: For most use cases, the default command works fine.
# Please refer "http://testng.org/doc/documentation-main.html#running-testng" for more options on running TestNG tests from the command line.
- echo "Unzipping TestNG tests jar"
- unzip tests.jar
- echo "Start Appium TestNG test"
- cd suites
- ls -l
- java org.testng.TestNG testng.xml
# The post test phase includes are commands that are run after your tests are executed.
post_test:
commands:
- ls -l
- zip -r allure.zip allure-results artifacts report test-output
- ls -l
- cp allure.zip $DEVICEFARM_LOG_DIR
- cd $DEVICEFARM_LOG_DIR
- ls -l
# The artifacts phase lets you specify the location where your tests logs, device logs will be stored.
# And also let you specify the location of your test logs and artifacts which you want to be collected by Device Farm.
# These logs and artifacts will be available through ListArtifacts API in Device Farm.
artifacts:
# By default, Device Farm will collect your artifacts from following directories
- $DEVICEFARM_LOG_DIR**
Thank you for reaching out. Are you trying to replace "java org.testng.TestNG testng.xml" with "./gradlew clean runTests testng.xml", or expecting to run gradle command locally?
I found solution:
You need to zip all project with your build.gradle files
Select Appium Node config, upload your zip
Use yaml config from TestNg or from my question, but replace command java org.testng.TestNG testng.xml to ./gradlew clean runTests(task in your gradle) your_test_suite.xml
We sometimes struggle with updating CSS / JS files for our customers when they're cached. A common hack we found is to append an version tag to the in our sourcecode (style.min.css becomes style.min.css?v=123 for example).
We wanted to integrate that change in our Gitlab CI/CD pipelines that we already use to sync the repository with our FTP server where the websites are hosted.
I came up with the following script (note: we're using the docker:latest image)
stages:
- deploy
before_script:
- apk update
- apk add lftp
deploy:
stage: deploy
script:
- sed -i -E 's/(\.css\?|\.css\")/\.css?v='$CI_JOB_ID'\&\"/g' templates/index.php
- sed -i -E 's/(\.js\?|\.js\")/\.js?v='$CI_JOB_ID'\&\"/g' templates/index.php
- lftp -c "set ftp:ssl-allow no; open -u $FTP_USER,$FTP_PASS $FTP_HOST; mirror -Rv ./ ./gitlab-ci-test --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
only:
- master
That's working fine, except when we use css/js files that already have an ?something=something in their reference. I want to keep that, but how...
style.min.css should become style.min.css?v=ID (this is working already with the file I have included above)
style.min.css?x=y should become style.min.css?v=ID&x=y
Can somebody help me out or come up with a better idea?
First handle the case style.min.css?x=y:
s/\.css\?/.css?v='$CI_JOB_ID'&/g
Then handle the case style.min.css:
s/\.css([^?])/.css?v='$CI_JOB_ID'$1/g
Has any one used stash builder plugin.Its documentation says that it adds some environment variables in to the build environment but if i echo them,they all are empty
echo "${sourceBranch}"
echo "${targetBranch}"
echo "${sourceRepositoryOwner}"
echo "${sourceRepositoryName}"
echo "${pullRequestId}"
echo "${destinationRepositoryOwner}"
echo "${destinationReposotryName}"
echo "${pullRequestTitle}"
echo "${sourceCommitHash}"
This plugin is doing nothing for me.Here is my configuration
I am selecting git as SCM [poll scm is not selected]
RepositoryUrl:ssh://git#stash-eng.abc.com:7999/mytool/my_tools_demo.git
Refspec:\+refs/pull-requests/*:refs/remotes/origin/pr/*
Branch Specifier:-origin/pr/${pullRequestId}/from
Then i mark the checkbox "Stash Pull Requests Builder"
and below is the value for diff fields
Cron:H/2 * * * *
Stash Host:stash-eng.abc.com
Stash Credentials:..........
Project:mytool
Repository Name:my_tools_demo
Still its doing nothing.Nor i ma seeing any thing related to plugin in logs.
I'm using this plugin in my company and it's working well.
In my Stash environment, all the project names are in uppercase.
If you have the same kind of project name, can you try to use them in uppercase? (in the Stash Pull Requests Builder section)
If you have one open pull request, can you try to add this comment to trigger a new Jenkins build?
test this please
This is a magic comment to trigger a new PR build from Stash.
I have got the same issue with Jenkins 2.7
According to below issue tracking in Github
https://github.com/nemccarthy/stash-pullrequest-builder-plugin/issues/84
it is fixed in one of the branch
https://github.com/eirikwang/stash-pullrequest-builder-plugin/tree/newChange
And will be merged into master soon..
How can one get the build_number (and other build metadata) from within the after_script command in Travis-CI?
What have been tried already:
The documentation on build configuration says this, in the IRC notification section:
You also have the possibility to customize the message that will be
sent to the channel(s) with a template:
notifications:
irc:
channels:
- "irc.freenode.org#travis"
- "irc.freenode.org#some-other-channel"
template:
- "%{repository} (%{commit}) : %{message} %{foo} "
- "Build details: %{build_url}"
You can interpolate the following variables:
repository: your GitHub repo URL.
build_number: build number.
branch: branch build name.
commit: shorten commit SHA
author: commit author name.
message: travis message to the build.
compare_url: commit change view URL.
build_url: URL of the build detail.
Trying to get this to work within an after_script command as below, did not work at all:
language: java
after_script:
- git commit -a -m "Committed by Travis-CI build number: %{build_number}"
It behaved as if .travis.yml file was absent/invalid (even though it did pass the Travis-CI YAML validation here).
It seems as though this should be doable, but could not find any sample that does this.
Could someone point me in the right direction?
The string replacements you can do for IRC output only work there unfortunately. They're only meant to be used for notifications in general, to customize the output, but are currently only available for IRC.
There's still a way to get the current build number, by accessing the TRAVIS_JOB_ID environment variable. If you change your script to the following line, things should work as expected:
after_success:
- git commit -a -m "Committed by Travis-CI build number: $TRAVIS_JOB_ID"
I use this in my deploy script:
git commit -am "Auto deploy from Travis CI build $TRAVIS_BUILD_ID"
More on Travis CI Documentation.