I'm putting together automated testing with behat - and encountered an issue I can't seem to find a solution to.
My behat.yml has all the usual stuff; I got directories for features and boostrap - and it all works.
Now, I have a separate directory, which contains additional classes that I need during the test execution. While I can, of course, use lots of require, I'm sure there's a better way to add a directory to the autoloader - yet I can't figure out how.
For example, I have the following directory structure:
test/
features/
bootstrap/
lib/
behat.yml
behat.yml contains this:
default:
autoload: [%paths.base%/boostrap]
suites:
web:
paths: [%paths.base%/features/web]
contexts: [Web\LoginContext]
api:
paths: [%paths.base%/features/api]
contexts: [Api\ApiContext]
Directory lib contains additional classes that I need to use in my tests. How can I add lib directory to the autoloader?
After much struggle, I kind of figured it out. I need to add this directory to my composer.json file:
"autoload": {
"psr-4": {
"MyNameSpace\\": "lib/"
}
}
and then run composer update.
Related
I'm having trouble configuring vite.config.js so that I can have both my Vue app and a service worker file live in the dist folder. My service worker was working with webpack previously but I've just upgraded to Vite and I'm having trouble configuring the build. My goal is to have my dist folder look like:
dist
|- index.html
|- sw.js
|- assets
|- app.[hash].js
I tried various different configurations but none of them have worked:
An approach that is recommended by Workbox. It seems like this doesn't work because of what is mentioned in this comment.
After reading that comment I tried to separate the logic out into a separate file (vite-sw.config.js) and running vite build -c vite-sw.config.js. This successfully generated the file I wanted but I couldn't figure out how to get that file mixed in with the original build. Is there a way to combine vite build and vite build -c vite-sw.config.js so that they both output to the same dist directory without overriding each other?
I found this alternative approach which successfully created the folder structure I wanted in dist but I was unable to adjust the format of the service worker file so I got Cannot use import statement outside a module (at sw.js:1:1) in the browser. Is there some way to use this method and somehow configure the format of the service worker file?
Any other ideas? I've been pretty stuck on this for a while. Thanks!
Try changing your configuration like this:
export default defineConfig({
build: {
rollupOptions: {
output:
{
format: 'es',
strict: false,
entryFileNames: "[name].js",
dir: 'dist/'
}
}
},
.
.
.
});
I'm looking to switch from Webpack to Snowpack for a development environment. But I have multiple entry points set up in Webpack and I haven't been able to find an example of how to do this in Snowpack. It seems that Snowpack is meant to be used with a true SPA that has only one HTML page and one entry point Javascript file.
Each HTML page on the site (20 altogether) has its own index.js that is the starting point for that page and is independent from the other pages on the site. How would this work in Snowpack?
I found some discussions on Github about multiple entry points, but reading through the comments I wasn't able to determine if this is supported or not. If it isn't supported, would I need to run Snowpack for each index.js? Or is there another fast development tool that would work in this use case?
If you check the config documentation, you will see the mount option is an object, meaning you mount multiple directories. If you have multiple top level modules in a mounted directory, you will get multiple entry points.
For example, following configuration takes any module from src folder and outputs it to dist folder in your build directory:
mount: {
src: { url: '/dist' },
},
Say you have src/index.tsx and src/module.tsx files, you will get dist/index.js and dist/module.js files in your output directory.
I just tested and it works.
I am new to Snowpack and I have a Template.html' file in my source folder that I would like Snowpack to read and produce an index.html` in the destination output folder. It would also be nice if I can use some variables in the template that Snowpack would simply substitute from the environment or configuration file. Any idea how to achieve this?
If I understand correctly, you are looking to use an alternative to index.html. I'm not sure if you are using react or a different framework, but in case you are using react, I found a solution.
This context is for flavor and is not related to the question, but I'll share in case it is helpful to others. In my case, I wanted to block the following warning on my production build (due to react-scripts, not snowpack):
Loading module from “http://localhost:3000/dist/index.js” was blocked because of a disallowed MIME type (“text/html”).
This is because snowpack requires the following script tag in index.html to generate your pages:
...
<script type="module" src="/dist/index.js"></script>
...
I don't need snowpack in production at this time ---I'm just here for the module hot reloading for now --- so I want to suppress this warning with an alternative index.html file, just for snowpack so that it has this script tag.
Solution:
So for your case where you want to use variables in snowpack --- but not your production build (or other run scripts for that matter) --- you can do the following:
Create a template with the above script in your index.html body, plus whatever other vars you need. Name it something other than "index.html". I went with indexsnowpack.html for simplicity.
Add the following route (Docs here) to your snowpack.config.js file in your apps root directory:
module.exports = {
...
routes: [
{
match: "routes",
src: ".*",
dest: "/indexsnowpack.html"
}
]
...
}
BEWARE: The above solution will match all paths to your new indexsnowpack.html file. So if you are not using a single-page application setup, you'll run into some hiccups. Further, if you have other routes defined (e.g., for api calls), place those above this route so that this route functions as a fallback for all calls except your api.
I have a problem, how could I cache multiple directories in gitlab ci? When Gitlab-runner download the repository, inside I have like 10 folders (diferent projects), some project depeneds of another, so I would like do it available for the next jobs.
I thought do it something like that, without specifying all folders manually
cache:
paths:
- "./"
Could be work this or I need something else?
Thanks in advance
If what you want is to cache all the untracked files and directories of the repository, yo can use untracked:true
job_name:
script: test
cache:
untracked: true
You can also combine this with the path keyword like this:
rspec:
script: test
cache:
untracked: true
paths:
- your_path/
You may use wildcards for the paths too like your_path/*.jar to take every .jar file in the directory.
I point you to the official GitLab documentation for more info: GitLab-CI documentation
I am trying to start PHPUnit testing.
I am using composer to load PHPUnit 4.5 , Yii 1.1.14 and some custom Yii packages that we have built.
Inside those custom packages, we autoload some files that set some aliases using the Yii class.
When running our application, we include the base Yii file manually, and then run the composer generated autoloads.
The trouble is, when we run PHPUnit.. the composer autoloads get run first. Even when specifying a bootstrap file with the include:
bin/phpunit --bootstrap carcass/phpunit.bootstrap.php
Leading to the following Exception:
Fatal error: Class 'Yii' not found
In fact it appears the autoloads are run even before the -- options are parsed:
bin/phpunit --help
results in the same error. Removing the autoloads allows PHPunit to run.
Is there any way around this?
I tried placing an autoload for the Yii base file in our main composer.json, but the sub-packages' autoloads get run first.. same error.
I also tried placing an autoload for the Yii base file in each of the sub-packages.. but then we get redeclaration errors as composer uses require. I'm also not a massive fan of this option as it rigidly defines where the Yii definition comes from to sub-packages that don't really need to know.
As the autoload classmap section is run first before all the files sections (including those from the sub-packages).
Placing the yii and YiiBase files in the classmap of the main composer.json for our project solved this issue:
"autoload": {
"classmap": [
"composer_packages/yiisoft/yii/framework/YiiBase.php",
"composer_packages/yiisoft/yii/framework/yii.php"
],
"files": [
...
]
}