Unable to load JSON files using karma-read-json plugin - jasmine

my folder structure looks like:
src
-cars
car.controller.js
car.controller.spec.js
car.test-data.json
in my spec file I am reading the json file as follows:
var sampleData = readJSON('./car.test-data.json')
However I keep receiving the error.. file not found.
I have tried a bunch of different paths.. none seem to be working

I finally went with an alternate solution I found on a blog:
mockedDashboardJSON.js:
'use strict'
angular.module('mockedDashboardJSON',[])
.value('defaultJSON',{
fakeData1:{'really':'fake2'},
fakeData2:{'history':'faked'}
});
Then in your test file:
beforeEach(module('yourApp','mockedDashboardJSON'));
var YourControlNameCtrl, scope, $httpBackend, mockedDashboardJSON;
beforeEach(function(_$httpBackend_,defaultJSON){
$httpBackend.when('GET','yourAPI/call/here').respond(defaultJSON.fakeData1);
//Your controller setup
....
});
it('should test my fake stuff',function(){
$httpBackend.flush();
//your test expectation stuff here
....
}

Related

JS React GLTF loader query parameters

I have the .gltf and .bin files in a azure storage account. Downloading these files requires a SAS URI that follows the pattern: https://<saName>.blob.core.windows.net/<pathToBlob>?<sas>. While I build a SAS that is valid for downloading both the .gltf and .bin files, I am running into an issue where I specify the .gltf URL to the useGLTF hook. That call goes through, but when fetching the .bin file, under the hood the loader is dropping the query params, resulting in a URL https://<saName>.blob.core.windows.net/<pathToBin> which fails.
Is there a way to make the loader keep the query parameters?
For anyone running into this, you can use the setURLModifier(). In my case, this looks as:
const { scene, animations } = useGLTF(props.path, false, false, (loader) => {
loader.manager.setURLModifier((url) => {
# alter the URL and return the new value
return url;
})
});

How to return an image to the client using Nest.js framework?

I am building an application, currently facing a problem I want to return an images which is stored in my server. I want to return image to React client, then it would be rendered in my component. But I can't figure out how to return the image itself. As far as I understand, I need to return image as JSON? But can't figure out how to do it in Nest.js framework.
First you should have a service, to serve static files. You can achieve this with Nest.JS. For example, if your images are placed in a public folder, placed in the root of your project, simply you can serve it, by adding the following line to your main.ts file:
import { join } from 'path';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.use('/public', express.static(join(__dirname, '..', 'public'))); // <-
await app.listen(3000);
}
Then for example you have cat.png placed in the public folder, and you want to send this in your response, you can send something like this:
{
image: `${baseUrl}/public/cat.png`
}
For example for your local server, baseURL will be http://localhost:3000.
You can take a look at this article for more detailed explanations.

Using http.GetFile how to prevent bad url requests from creating new files

I am using the http.getFile function to download files from an api. I am having a issue where files are still created, even though the url passed to getFile is invalid or returning errors. After some research it appears the getFile will always create a new file, is there a way to prevent getFile from creating a new file if the url is invalid?
The only work around I can think is to check the file size after calling the getFile and deleting it if there is no data?
In the example below I was tying to use the File.exists, but it always returns true.
return http.getFile(fullUrl, filePath)
.then(function(r){
// Test - Check if file Exists
console.log("Check File Exist: " + fs.File.exists(filePath));
}, function(error) {
});
Just check if the "fullUrl" is a valid url before requesting:
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*#)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%#!\-\/]))?/
var isUrlValid = regexp.test(fullUrl);
if(isUrlValid){
http.getFile(fullUrl, filePath)
}

Systemjs-builder, basic useage / configuration

Hello I'm trying to test the systemjs-builder, the readme has a nice getting started section but where do I put the builder code?
https://github.com/systemjs/builder
The code I'm referring to is below, I'm not sure where to put this (is this the builder.config?):
var path = require("path");
var Builder = require('systemjs-builder');
// optional constructor options
// sets the baseURL and loads the configuration file
var builder = new Builder('path/to/baseURL', 'path/to/system/config-file.js');
builder
.bundle('local/module.js', 'outfile.js')
.then(function() {
console.log('Build complete');
})
.catch(function(err) {
console.log('Build error');
console.log(err);
});
Is there a demo build out there that I can look at?
You'd put that in your front-end building pipeline. For instance, inside of a gulp task.
While in a development build you could just serve all your files separately, in a production build you'd bundle and minify them to reduce the number of HTTP requests.

Cloud code: can I use other files besides main.js?

Does all my cloud clode have to be in main.js or can I create other logical files and somehow add them into my cloud code?
If you just want to split your Parse.Cloud functions in multiple files, you also can do that and just require the file in your main.js.
So you can have this in your cloud/main.js
require('cloud/userFunctions.js')
and have all the related functions in your cloud/userFunctions.js
Parse.Cloud.define("processUserRequest", function(request, response) {
// do your stuff
});
You can split your code into different files using require.
The example below come from Parse documentation
If you have some code in cloud/name.js
var coolNames = ['Ralph', 'Skippy', 'Chip', 'Ned', 'Scooter'];
exports.isACoolName = function(name) {
return coolNames.indexOf(name) !== -1;
}
You can then you it in cloud/main.js
var name = require('cloud/name.js');
name.isACoolName('Fred'); // returns false
name.isACoolName('Skippy'); // returns true;
name.coolNames; // undefined.

Resources