使用以下配置,在更改 mShareLoadingPB.setVisibility(View.VISIBLE);
Log.d("ShareImageTask", "onPreExecute: " + System.currentTimeMillis());
Observable.fromCallable(() -> {
Uri bmpUri = null;
try {
// Use methods on Context to access package-specific directories on external storage.
// This way, you don't need to request external read/write permission.
File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image_" + System.currentTimeMillis() + ".png");
FileOutputStream out = new FileOutputStream(file);
resource.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.close();
// wrap File object into a content provider. NOTE: authority here should match authority in manifest declaration
bmpUri = ImageFileProvider.getUriForFile(PhotoFullScreenActivity.this, getApplicationContext().getPackageName() + ".fileprovider", file); // use this version for API >= 24
} catch (IOException e) {
e.printStackTrace();
mShareLoadingPB.setVisibility(View.GONE);
}
return bmpUri;
})
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new DefaultObserver<Uri>() {
@Override
public void onNext(Uri uri) {
mShareLoadingPB.setVisibility(View.GONE);
mShareIntent = new Intent();
mShareIntent.setAction(Intent.ACTION_SEND);
mShareIntent.putExtra(Intent.EXTRA_STREAM, uri);
mShareIntent.setType("image/*");
startActivity(Intent.createChooser(mShareIntent, "Share image"));
}
@Override
public void onError(Throwable e) {
Log.e("Error","Error");
}
@Override
public void onComplete() {
}
});
cli选项时,覆盖率报告会中断。我尝试设置testMatch
选项,但这也不能解决问题。
./ src / sum.js
collectCoverageFrom './src/*.js'
./ test / sum.js
function sum(a, b) {
return a + b;
}
module.exports = sum;
package.json
const sum = require('../src/sum');
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
来自"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-decorators": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"jest": "^23.6.0"
},
"scripts": {
"test": "jest ./test/*.js --testMatch '**/*.js' --coverage --coverageDirectory './test-coverage'"
}
的输出
npm run test
答案 0 :(得分:1)
设置testRegex
参数:
jest --testRegex='./test/.*\.js$' --coverage --coverageDirectory './test-coverage'
现在输出看起来像这样:
PASS test/sum.js
✓ adds 1 + 2 to equal 3 (3ms)
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
sum.js | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.769s, estimated 1s
Ran all test suites.