my gulp file:
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
//server
gulp.task('run', function() {
browserSync.init({
proxy: "http://localhost/test-site/"
});
gulp.watch("./*.php").on('change', browserSync.reload);
});
when running gulp run from terminal it's fire the browser and shows the page as expected but without the "connected to browserSync" msg and when saving some changes the gulp watch fires and the terminal shows [BS] Reloading Browsers... but the browser not refreshing the page
now on the other hand when i'm changing the file extension to "html" and gulp watch to gulp.watch("./*.html").on('change', browserSync.reload);
it all work as expected: when running the task it's fire the browser, this time with the "connected to browserSync" msg and when saving some changes it refresh the page.
early today i did manage to refresh the page on php file change but i lost it and can't find the reason why it's not working any more, i couldn't find any post about it on google
any ideas ?
Create reload and projectPHPWatchFiles objects
var projectPHPWatchFiles = './**/*.php'; // Path to all PHP files.
var reload = browserSync.reload; // For manual browser reload.
Then in your watch process, add this
gulp.watch( projectPHPWatchFiles, reload); // Reload on PHP file changes.
And it will start refreshing on changes.
If you use WordPres, I have a handy repo for WPGulp which takes care of all this.
Related
Background
I have my project deployed to Github Pages here: https://zeddrix.github.io/jw-guitar-tabs, so I have this in my svelte.config.js file:
kit: {
...
paths: {
base: '/jw-guitar-tabs'
},
appDir: 'internal',
...
}
I have this in my __layout.svelte:
<script lang="ts">
import { base } from '$app/paths';
...
const fetchFromDBAndStore = async (category: SongCategoriesType) => {
const res = await fetch(`${base}/api/categories/original-songs`);
const data = await res.json();
console.log(data);
...other code...
};
...I have my code here that uses this data...
</script>
<Layout><slot /></Layout>
Side note: I put it in this file so that this runs on any page, but I have a code to make sure that this doesn't run if I already have the data. This is not the issue.
This calls on the file: src/routes/api/categories/original-songs.ts:
import fetchSongsDB from '$utils/fetchSongsDB';
export const get = async () => fetchSongsDB('originals');
And this fetchSongsDB function fetches the songs from my database.
Everything is working fine in development mode when I run npm run dev and even in preview mode when I run npm run preview after build, of course, in localhost:3000/jw-guitar-tabs.
Issue
However, on the static github page at https://zeddrix.github.io/jw-guitar-tabs, I get this:
It serves the 404 Github Page as the response. I guess it's because it can't find the src/routes/api/categories/original-songs.ts file. But of course Github will not find this file because the deployed folder to gh-pages is the build folder so I don't have this original file route anymore.
How would I solve this?
Rename original-songs.ts to original-songs.json.ts
Change the
fetch(`${base}/api/categories/original-songs`);
to
fetch(`${base}/api/categories/original-songs.json`);
That allows the adapter-static to generate the json files at build time.
(These are static files, to see changes made in mongodb will require a rebuild & redeploy to GitHub pages)
Sometimes the static adapter doesn't autodetect the endpoint.
You can help the adapter by specifying the url in svelte.config.js
kit: {
prerender: {
entries: [
"*",
"/api/categories/original-songs.json",
Bonus tip: The /favorites url redirects to /favorites/ when refreshing the page, add trailingSlash: "never", to kit to generate favorites.html instead of favorites/index.html and keep the /favorites url on refresh.
I'm building a React app that hits a Flask server for Stripe payment processing and Apple Wallet pass generation. My server script generates the file, and saves it to a directory, then returns the name of the pkpass file to the client, which attempts to download it and load it into Wallet.
Passes seem to be generating correctly. I can download them (sftp) and drop them on the Simulator and they open up just fine. I can un-zip them and all the necessary components seem to be there and seem valid.
However, with the web app, I cannot get them to download and install into Wallet. On my iPhone, I get a simple "Safari could not download the file" error.
If I use Safari on the desktop, the pkpass file gets downloaded to my Mac. When I drag & drop it on the simulator, I see the following error in Console:
BOM could not extract archive: Couldn't read PKZip signature
Failed to add pass: 'file:///Users/tpoulsen/Downloads/ch_1FPYBoAzcfAbJsLnXDsVRcrc.pkpass' Error Domain=PKPassKitErrorDomain Code=1 "The pass cannot be read because it isn’t valid." UserInfo={NSLocalizedDescription=The pass cannot be read because it isn’t valid., NSUnderlyingError=0x6000016dbbd0 {Error Domain=PKPassKitErrorDomain Code=1 "(null)"}}.
I used VBinDiff to compare the downloads (via sftp and Safari) and the files are quite different. So, the problem appears to be either with my Flask app or my web app.
Here's my Flask route
#application.route("/passes/<path:fname>")
def passes_proxy(fname):
"""static passes serve"""
return send_from_directory("passes", fname, mimetype="application/vnd.apple.pkpass")
And in my component:
paymentRequest.on('token', async (ev) => {
try {
const response = await fetch('https://my_server.com/charge', {
method: 'POST',
body: JSON.stringify({
token: ev.token.id,
amount: totalInCents,
description: purchasedItems.join(',\n')
}),
headers: {'content-type': 'application/json'},
});
if (!response.ok) {
throw new Error('Network response was not ok.');
}
ev.complete('success');
const pkpass = await response.json();
download(`https://my_server.com/passes/${pkpass.filename}`, pkpass.filename, "application/vnd.apple.pkpass");
} catch (error) {
throw new Error("There was a problem processing your payment");
}
});
Tech involved:
create-react-app / React
Flask with wallet-py3k for pass generation
download.js to download the generated file
Got it. I was being too fancy. Instead of using download.js to grab the file, I simply needed to:
window.location.href = `https://my_server.com/passes/${pkpass.filename}`;
My add-on involves the user interface, and so to test it I decided to simply have a html page which will load and the tester can follow some instructions on the page.
Here is an example of loading the page:
exports["test interaction"] = function(assert, done) {
require("sdk/tabs").tabs.open({
url: "./tests/test-page.html",
onClose: function(tab) {
assert.pass("Done page test");
done();
});
};
However, after about 16 seconds the tests will always fail with two error messages:
fail:
Timed out (after: START)
and
fail:
Should not be any unexpected tabs open
Furthermore, and more importantly, my addon does not work at all using cfx test, while it works using cfx run on the same test pages.
Is there a way to load some HTML testing pages using cfx test?
Adding tab.close() before done() will fix the "Should not be any unexpected tabs open" error.
I think what you need to do is listen for messages from the tab you opened and then manually close the tab. You can send messages by injecting a content script into the tab, and communicating back. Something like:
page is opened
page runs some tests, and on completion or error, sends data via window.postMessage to the content script
the content script relays these results back to the tab worker
the tab worker closes the tab
I found an interesting issue when attempting to login using PhantomJS. I'm at a loss as to why it's actually occurring.
Basically you start up a remote debugger like so:
/usr/local/bin/phantomjs --web-security=no --remote-debugger-port=13379 --remote-debugger-autorun=yes /tmp/test.js
Within the remote debugger:
> location.href = "https://www.mysite.com/login"
> $('input[name="username_or_email"]').val('blah#email.com')
> $('input[name="password"]').val('wrongpassword')
> $('button[type="submit"]').submit()
Doing this in Chrome will give me the correct "wrong password" message after the XHR request, whereas using phantomjs gives me a generic error as no cookie is sent with phantomjs (I examined the headers).
I'm quite confused on why phantomjs doesn't send the cookie with the POST request. Does anyone know how we can get phantomjs to send the cookie with ALL requests as it should? Setting a cookie-file doesn't make any difference either.
Ok, this seems to be something related with session cookies and not regular cookies.
Heres a huge thread on the developer in charge of the cookies feature of phantomjs and some guys with the same issue as yours.
https://groups.google.com/forum/#!msg/phantomjs/2UbPkIibnDg/JLV9jBKxhIQJ
If you dont want to skirm through the entire file, basically:
Phantomjs behaves like a regular browser, and it deletes all session cookies when browser closes, in your case, when your script execution ends.
So, even if you set the --cookies-file=/path/to/cookies.txt option you will only store regular cookies on it, for subsecuent executions.
There are two possible approaches for you. One, is to make all requests within the same script, or the other is to store and restore the cookies manually.
On the thread there are a couple of functions that you can use to do this.
function saveCookies(sessionCookieFile, page) {
var fs = require("fs");
fs.write(sessionCookieFile, JSON.stringify(page.cookies));
}
function restoreCookies(sessionCookieFile, page) {
var fs = require("fs");
var cookies = fs.read(sessionCookieFile);
page.cookies = JSON.parse(cookies);
}
var page = require('webpage').create();
And, if everything fails...
You could download source code and recopile phantomjs
You will need to edit src/cookiejar.cpp and remove or comment purgeSessionCookies();
Hope, this helps.
How can I clear cookies for each tests in my PhantomJS + GhostDriver + Selenium WebDriver + WebDriver Client system?
My test process looks like this:
Start selenium-web-driver-standalone in hub role.
Start phantomjs in webdriver mode and attach it to selenium
webdriver.
Start shell script that iterates over tests suites and start each.
Each test uses webdriver client and communicate with browser
connected to selenium web driver.
When I use firefox browser instead of phantomjs all tests passed ok. But when I switch to using phantomjs as browser all tests that checked registration failed because cookies already set after first test execution. Can I clear all cookies on every test start up? Or I should to restart phantomjs process on every separate test (as this is with firefox and selenium webdriver in not hub role)?
Maybe some offtopic, cause author marked that he uses php to run test.
But if you came from google and interested in C# solution to clear all cookies, look below:
// driver is fully initialized PhantomJS instance
driver.Manage().Cookies.DeleteAllCookies();
Requires NuGetPackages:
PhantomJS 2.0.0
Selenium.Support 2.48.2
Selenium.WebDriver 2.48.2
Tested with .NETFramework v4.5.2
You can delete specific cookie using:
webDriver.manage().deleteCookieNamed("smSession");
And to delete all the cookies using:
webDriver.manage().deleteAllCookies();
I had similar problem with GhostDriver not being able to clear localStorage. Try these suggestions:
After you driver.get(URL) to your page, you can execute javascript in
it from webdriver, like this
function clearCookie(name, domain, path){
var domain = domain || document.domain;
var path = path || "/";
document.cookie = name + "=; expires=" + +new Date + "; domain=" + domain + "; path=" + path;
};
There is no 100% solution to delete browser cookies.
The problem is that cookies are uniquely identified by not just by
their key "name" but also their "domain" and "path".
Without knowing the "domain" and "path" of a cookie, you cannot
reliably delete it. This information is not available through
JavaScript's document.cookie. It's not available through the HTTP
Cookie header either!
However, if you know the name, path and domain of a cookie, then you
can clear it by setting an empty cookie with an expiry date in the
past
Resources:
https://sqa.stackexchange.com/a/10468
https://stackoverflow.com/a/2421786/572348