我正在学习Docker.很多次,我看到它Dockerfile有WORKDIR命令
FROM node:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
EXPOSE 3000
CMD [ “npm”, “start” ]
Run Code Online (Sandbox Code Playgroud)
我不能省略WORKDIR,Copy只是让我Dockerfile的项目根源?使用这种方法的缺点是什么?
我正在使用Jest测试我的GraphQL api.
我正在为每个查询/突变使用单独的测试套装
我有2次测试(每一个在一个单独的测试套),其中我嘲笑一个函数(即,流星的callMethod),其在突变使用.
it('should throw error if email not found', async () => {
callMethod
.mockReturnValue(new Error('User not found [403]'))
.mockName('callMethod');
const query = FORGOT_PASSWORD_MUTATION;
const params = { email: 'user@example.com' };
const result = await simulateQuery({ query, params });
console.log(result);
// test logic
expect(callMethod).toBeCalledWith({}, 'forgotPassword', {
email: 'user@example.com',
});
// test resolvers
});
Run Code Online (Sandbox Code Playgroud)
当console.log(result)我得到
{ data: { forgotPassword: true } }
Run Code Online (Sandbox Code Playgroud)
这种行为不是我想要的,因为在.mockReturnValue我抛出一个错误,因此期望result有一个错误对象
然而,在此测试之前,另一个是运行
it('should throw an error if wrong credentials …Run Code Online (Sandbox Code Playgroud) 运行此查询时:
const project = await models.Projects
.updateOne(
{ _id: projectId },
{
$addToSet:
{
membersIds:
{
$each: membersIds
},
},
},
);
Run Code Online (Sandbox Code Playgroud)
我得到的答复如下:
{ n: 1, nModified: 1, ok: 1 }
Run Code Online (Sandbox Code Playgroud)
是否可以获得更新的对象而不是这个猫鼬数据?
我正在考虑实现同时包含错误和数据的 graphql 响应的方法。
是否可以在不创建包含error?
例如
MutationaddMembersToTeam(membersIds: [ID!]! teamId: ID!): [Member]将成员添加到某个团队。假设这种突变被称为有以下membersIds:[1, 2, 3]。
id为1和2的成员已经在团队中,所以必须抛出无法添加这些成员的错误,但应该添加id为3的成员,因为他不在团队中。
我正在考虑使用,formatResponse但似乎我无法在那里得到错误。
是否可以在不向返回类型添加错误字段的情况下解决此问题?
我正在编写单元测试来检查我的api.在我将我的git 测试分支与我的dev分支合并之前,一切都很好,但后来我开始收到此错误:
App running at: http://localhost:4096/
spacejam: meteor is ready
spacejam: spawning phantomjs
phantomjs: Running tests at http://localhost:4096/local using test-in-console
phantomjs: Error: fetch is not found globally and no fetcher passed, to fix pass a fetch for
your environment like https://www.npmjs.com/package/unfetch.
For example:
import fetch from 'unfetch';
import { createHttpLink } from 'apollo-link-http';
const link = createHttpLink({ uri: '/graphql', fetch: fetch });
Run Code Online (Sandbox Code Playgroud)
这是我api.test.js文件的一部分:
describe('GraphQL API for users', () => {
before(() => …Run Code Online (Sandbox Code Playgroud) 我想从 XML 文件创建一个树视图,我做到了。然而,当我决定让它更灵活时,我遇到了一些问题。
这是我的组件:
Vue.component('elname', {
props: ['text'],
template: '<span>{{ text }}</span>'
})
Vue.component('recursive', {
props: ['d', 'liname', 'openclose'],
template: '#recursive',
data: function() {
return {
seen: true
}
}
}
)
Run Code Online (Sandbox Code Playgroud)
Vue 对象如下所示:
var appp = new Vue({
el: '#here',
data: function(){
return {
friends: '',
}
},
beforeMount() {
parser = new DOMParser();
var response = "<scope><friend><name>Alex</name><hobbies><h>music</h><h>salsa</h></hobbies></friend><friend><name>Natasha</name><hobbies><h>hiking</h></hobbies></friend></scope>";
xml = parser.parseFromString(response, 'text/xml');
children = xml.getElementsByTagName('scope')[0];
this.friends = children;
}
})
Run Code Online (Sandbox Code Playgroud)
我seen在recursive组件中有这个变量
Vue.component('recursive', {
props: ['d', …Run Code Online (Sandbox Code Playgroud) 我已经format on save启用,它在 .js 文件中工作正常,但是当我尝试将代码保存在我的 .jsx 文件中时,一切都变得一团糟。如何在不禁用的情况下配置我的 prettier 以避免此问题format on save?
是否可以使用 nodemon 在更改时运行脚本?
是否有可能做这样的事情:nodemon --watch src --exec yarn run my-script?
因此,理想情况下,我只想在src文件夹发生更改时运行脚本
假设我有两个函数,foo称为bar。我有一个流星的应用程序,所以我决定用流星mocha沿着封装sinon和chai不jest
// foo.js
const foo = () => // call to a google maps api;
export default foo;
// bar.js
const bar = (x) => {
foo();
...
};
export default bar;
Run Code Online (Sandbox Code Playgroud)
foo在这种情况下,模拟的正确方法是什么?
目前,我想出了以下解决方案:
import foo from 'path/to/foo.js'
import bar from 'path/to/bar.js'
describe('my test suite', function() {
it('should pass the test', function() {
foo = spy();
bar(5);
assert(foo.calledOnce);
});
});
Run Code Online (Sandbox Code Playgroud)
以下代码有效,但是重新定义foo是否正确?
更新
另外,不可能以此方式创建模拟或存根,这使我认为Sinon不适合模拟独立函数
我将 pdf 文件上传到 S3 时遇到问题。
我可以PDFkit在本地使用和存储它们来创建 pdf 文件(我可以在浏览器中查看它们)。
但是,当我尝试将它们上传到我的 S3 存储时,出现此错误:无法加载 PDF 文档。在我的浏览器中打开 pdf 时。您可以查看: https://s3.us-east-2.amazonaws.com/pdf-twitter-bucket/twitter/HvkH98YA0p.pdf
fs.readFile('../pdf/' + fileName, 'utf8', function (err, contents) {
const buf = new Buffer(contents, 'base64');
// define params
const params = {
Bucket: 'pdf-twitter-bucket',
Key: 'twitter/' + fileName,
Body: buf,
ContentType: 'application/pdf',
ACL: 'public-read'
};
s3bucket.upload(params, function (err) {
if (err) {
console.log('error in callback');
console.log(err);
}
res.end(
'https://s3.us-east-2.amazonaws.com/pdf-twitter-bucket/twitter/' +
fileName
); // send the link to s3
});
});
Run Code Online (Sandbox Code Playgroud)
我尝试了很多选项:1)使用 …
javascript ×4
meteor ×3
node.js ×3
graphql ×2
amazon-s3 ×1
apollo ×1
aws-sdk ×1
docker ×1
dockerfile ×1
graphql-js ×1
jestjs ×1
mongoose ×1
nodemon ×1
package.json ×1
prettier ×1
reactjs ×1
recursion ×1
sinon ×1
testing ×1
unit-testing ×1
vue.js ×1
vuejs2 ×1