How to configuring prettier for graphql files? - prettier

I have Prettier installed as a plugin in VS Code, in addition I also installed it as an NPM package but it does not format the file (following) correctly. there should be commas between each line.
I tried the Plugin and NPM package, together and separately but it didn't make a difference.
schema.gql
type Mutation {
addBook(
title: String
subtitle: String
author: String
editor: String
thumbnail: String
category: String
...
): Book
}

Related

How to specify test tags correctly in dart_test.yaml?

I have a dart project that has several tests, when I try to run an isolated test I get this warning:
Warning: A tag was used that wasn't specified in dart_test.yaml.
"tagName" was used in the suite itself
how should i declare these tags correctly in dart_test.yaml?
Steps
Create a file dart_test.yaml at the root of your project
Add your tags one after another under a tags field
Add tags to your test or testWidget declaration
Run your tests with the -t flag followed by the wanted tag
Sample
Let's say I want to add the following tags: golden, atom, molecule, organism, mobile, desktop. My dart_test.yaml will look like this:
tags:
golden:
atom:
molecule:
organism:
mobile:
desktop:
And everything should be okay you can write your test:
void main() {
testWidgets(
'this is a test',
(tester) async {
// ...
},
tags: ['atom', 'mobile'],
);
}
You can run it with the following command:
$ flutter test -t mobile
source

How to get appVersion from chart yaml file on azure devops?

I want to get appVersion from chart.yaml file and compare with version which getting from project.csproj file.
So, I create three tasks that
version reader which getting version from project.csproj
file content to variable to get content from chart.yaml
powerscript shell that compare version and appVersion
file content to variable get all content. I only want to get appversion.
How to possible like this $env:helmchart_appVersion
How can I get appVersion from chart.yaml ?
here my example.
$env:Project_Version is getting from Version Reader
$env:helmchart is getting from File content to variable
chart.yaml file :
apiVersion: v2
name: asset-api
description: Helm Chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.5.2
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.0.2"
compare script:
write-host($env:helmchart)
write-host($env:helmchart -match "appVersion: ")
write-host($env:Project_Version)
if($env:helmchart -match "appVersion: " + $env:Project_Version) {
write-host('Helm Chart appVersion Validated!')
}
else {
write-error 'Helm Chart appVersion not matched with your project version! Check Chart.yaml file!'
}
I noticed that, the missing double quote failed to give error.
$env:Project_Version is 1.0.2
$env:helmchart is appVersion: "1.0.2"
So the script should be:
if($env:helmchart -match 'appVersion: "' + $env:Project_Version '"')
{
write-host('Helm Chart appVersion Validated!')
}
else
{
write-error 'Helm Chart appVersion not matched with your project version! Check
Chart.yaml file!'
}

Building a package.json and Gruntfile using Yeoman

New to Yeoman as of today. I am building a generator that will create a new package.json with data that will help build the applications Gruntfile. For (probably) unnecessary reasons, I separated out the Yeoman pieces into 2 files. Below is an excerpt from index.js...
// index.js
myGenerator.prototype.packagejson = function packagejson() {
var projectName = this.projectName;
var pkg = {
"name": projectName,
"version": "0.0.0",
"dependencies": {},
"srcDir": process.cwd(),
};
this.write('package.json',JSON.stringify(pkg));
};
myGenerator.prototype.gruntfile = function gruntfile(){
this.template('Gruntfile.js','Gruntfile.js');
}
This creates a package.json file and writes the JSON string to the file. projectName is a prompt asked when the template is loaded in the command line. Process.cwd() refers to the current file directory.
Then it creates a Gruntfile from a template. Except below:
//Grunt - Yeoman template
module.exports = function(grunt){
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sync:{
dev:{
files:[
{src:['./index.html','./app.css','./js/*.js'],dest:'m:/dev/project/'},
{cwd:"<% pkg.srcDir %>", src:['**/*.js','**/*.css','**/*.html'], dest:'m:/dev/project/'}
]
}
}
})
};
This, in my mind should...
Create a path that was generated by index.js (via process.cwd()) that was printed to the package.json file. This is read into the gruntfile via grunt.file.readJSON.
Then the path reference (string) should be accessible through the object property: pkg.srcDir.
However, I only get back an empty string.
// Gruntfile.js for new application
cwd:"", src:['**/*.js','**/*.css','**/*.html'], dest:'m:/dev/project/'
Any obvious reason why I am not able to read in the package.json info and populate my gruntfile?
Thanks
Add double percent in the opening template tag
<%% pkg.srcDir %>

Exclude classes from EMMA in Gradle build

I build my project with Gradle 1.0 and I use the EMMA plugin for code coverage info. I would like to exclude certain files from the coverage report.
How can I achieve that?
Are you including this Gradle script? I think you can exclude classes within your instrumentation definition (see example below). However, it doesn't look like you can set the exclude pattern by using a convention property.
ant.emma(enabled: 'true', verbosity:'info'){
instr(merge:"true", destdir: emmaInstDir.absolutePath, instrpathref:"run.classpath",
metadatafile: new File(emmaInstDir, '/metadata.emma').absolutePath) {
instrpath {
fileset(dir:sourceSets.main.output.classesDir.absolutePath, includes:"**/*.class", excludes:"**/Some*.class")
}
}
}
If I were you I'd try to fork the plugin, add a new field to EmmaPluginConvention that lets you set the exclude pattern and then use that variable in the instrpath definition. After changing the code and verifying that it works send a pull request to the author. I am sure he will incorporate your change.
This doesn't work with gradle 1.5. Emma takes a filter like so:
ant.emma(enabled: 'true', verbosity: $verbosityLevel) {
instr(merge: "true", destdir: emmaInstDir.absolutePath, instrpathref: "run.classpath",
metadatafile: new File(emmaInstDir, '/metadata.emma').absolutePath, filter: "-com.someclass.*" ) {
instrpath {
fileset(dir: sourceSets.main.output.classesDir.absolutePath, includes: "**/*.class" )
}
}
}
the filter follows the definition from this page:
http://emma.sourceforge.net/reference/ch02s06s02.html

How to Write Unit Tests for Kanso

I've written a lot of django applications and become accustomed to extending unittest.TestCase and running python manage.py test app_name. Is there a similarly simple way to unit test Kanso apps? Please provide a minimal example.
Thanks.
Kanso apps are CouchDB apps. However the best bang-for-buck is to ignore CouchDB for now. The important thing is this: Kanso apps are Node.js apps. Test them the same way you would test a Node.js app. Test that they adhere to the documented CouchDB API and you will be fine.
Ideally, we might want to run tests actually in CouchDB. The JavaScript engines are different (V8 vs. SpiderMonkey); the environments are different. However in practice, it is so much easier to test Node.js code. (Also, a whole class of JavaScript bugs are absent on both platforms: third-party code setting global variables, changing built-in types, changing prototypes—those are all browser issues. Node.js and CouchDB are both pristine and predictable.)
Example
Let's make a simple Couch app that outputs "Hello world" in a _show function.
The kanso.json file:
{ "name" : "hello_world"
, "version": "0.1.0"
, "description": "A simple hello-world Couch app"
, "dependencies": { "node-couchapp": "~0.8.3" }
, "app": "app"
}
Next run kanso install which will pull in the "node-couchapp" dependency. (Notice how using the kanso command is similar to using the npm command.)
Let's make a very simple Couch app, in ./app.js:
// A Couch app that just says hello in a _show function.
module.exports = {
'shows': {
'hello': function(doc, req) {
var who = req.query.who || "world"
return "Hello, " + who
}
}
}
I ran kanso push http://example.iriscouch.com/so_hello and I can see my app here:
http://example.iriscouch.com/so_hello/_design/hello_world/_show/hello
http://example.iriscouch.com/so_hello/_design/hello_world/_show/hello?who=Stack+Overflow
Adding Tests
I like node-tap so let's use that. But the main point is, this is just some Node.js code. Test it using whatever method your prefer.
First, a quick package.json file:
{ "name" : "hello_world"
, "description": "A simple hello-world Couch app"
, "version": "0.1.0"
, "private": true
, "devDependencies": { "tap": "~0.2.3" }
}
Run npm install to get the node-tap package. (And I always have ./node_modules/.bin in my $PATH when I work on Node.js. Rather than a global install, I like to have everything I need right there in the project.
Next, perhaps a test/show_function.js file:
var tap = require('tap')
tap.test('The Couch app loads', function(t) {
t.doesNotThrow(load_app, 'No problem loading the app.js file')
t.end()
function load_app() {
var app = require('../app')
}
})
tap.test('The show function', function(t) {
var app = require('../app')
, hello = app.shows.hello
t.type(hello, 'function', 'Show function "hello" in the couch app')
var doc = {}
, null_req = {'query':{}}
, john_req = {'query':{'who':'John Doe'}}
t.equal(hello(doc, null_req), 'Hello, world', '"Hello world" by default')
t.equal(hello(doc, john_req), 'Hello, John Doe', 'Supports ?who query string')
t.end()
})
Test it by running tap test:
$ tap test
ok test/show_function.js ................................ 5/5
total ................................................... 5/5
ok
I'll change the code to return "Hello, world" hard-coded (i.e., ignore the req.query.who parameter). Notice the failing test:
$ tap test
not ok test/show_function.js ............................ 4/5
Command: "node" "show_function.js"
ok 1 No problem loading the app.js file
ok 2 Show function "hello" in the couch app
ok 3 "Hello world" by default
not ok 4 Supports ?who query string
---
file: /private/tmp/j/test/show_function.js
line: 23
column: 5
stack:
- getCaller (/private/tmp/j/node_modules/tap/lib/tap-assert.js:403:17)
- assert (/private/tmp/j/node_modules/tap/lib/tap-assert.js:19:16)
- Function.equal (/private/tmp/j/node_modules/tap/lib/tap-assert.js:160:10)
- Test._testAssert [as equal] (/private/tmp/j/node_modules/tap/lib/tap-test.js:86:16)
- Test.<anonymous> (/private/tmp/j/test/show_function.js:23:5)
- Test.<anonymous> (native)
- Test.<anonymous> (events.js:88:20)
- Test.emit (/private/tmp/j/node_modules/tap/lib/tap-test.js:103:8)
- GlobalHarness.<anonymous> (/private/tmp/j/node_modules/tap/lib/tap-harness.js:86:13)
- Array.0 (native)
found: Hello, world
wanted: Hello, John Doe
diff: |
FOUND: Hello, world
WANTED: Hello, John Doe
^ (at position = 7)
...
ok 5 test/show_function.js
1..5
# tests 5
# pass 4
# fail 1
total ................................................... 4/5
not ok
I have some projects that may help showcase testing kanso apps:
Dashboard Core Project
https://github.com/ryanramage/dashboard-core
Features:
Travis Support.
PhantomJS headless testing using NodeUnit
Since this is a module, we have a test folder, that is a seperate kanso app that uses the module. Note in the packages folder there is a symlink back to the root of the project.
Node-Couchapp Project
https://github.com/kanso/node-couchapp
Travis support
This time multiple test kanso projects in the kanso folder. Again using the symlink trick in the package directory
Like JasonSmith, I also recommend you test using Node.js where possible. However, due to the nature of CouchApps you often end up having to write unit tests to run in the browser, either because they interact with browser APIs you don't want to mock or because you need to test it works in a range of browsers.
When doing browser-based unit tests I use a few little Kanso packages I hacked together to automatically present an interface for running nodeunit test suites. It's a bit rough around the edges at the moment but gets the job done.
kanso.json
Add nodeunit and nodeunit-testrunner packages to your kanso.json file and run kanso install to fetch them from the repositories.
{
"name": "example",
"version": "0.0.1",
"description": "example app with unit tests",
"modules": ["lib", "tests"],
"load": "lib/app",
"dependencies": {
"modules": null,
"properties": null,
"nodeunit": null,
"nodeunit-testrunner": null
}
}
Notice that I've included the 'tests' directory as a module path. Any modules dropped into that directory will be used as nodeunit test suites and displayed by the nodeunit-testrunner UI.
Rewrites
You need to manually add the nodeunit-testrunner package's rewrites to your app, in my example that means editing lib/app.js to look like the following:
exports.rewrites = [
require('nodeunit-testrunner/rewrites')
];
Add some tests
Assuming we have a module lib/foo.js that looks like this:
exports.hello = function (name) {
return 'hello ' + name;
};
We could add a test by adding a module at tests/test-foo.js (this can be named anything so long as it's inside the tests directory).
var foo = require('lib/foo');
exports['test for foo.hello'] = function (test) {
test.equal(foo.hello('bar'), 'hello bar');
test.done();
};
If you then push your app and visit http://localhost:5984/example/_design/example/_rewrite/test in the browser you will be presented with a basic interface for running the test suites in the tests directory, either individually or all of them one after another.
Hope that helps.