Skip to content

Commit 980c7d5

Browse files
authored
Migrate testing to rules-unit-testing (#3378)
1 parent 5d4d182 commit 980c7d5

File tree

14 files changed

+1324
-16
lines changed

14 files changed

+1324
-16
lines changed

.changeset/cold-bats-hammer.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@firebase/rules-unit-testing': major
3+
---
4+
5+
Release `@firebase/rules-unit-testing` to replace the `@firebase/testing` package. The new
6+
package is API compatible but has the following breaking behavior changes:
7+
8+
* `assertFails()` will now only fail on `PERMISSION DENIED` errors, not any error.
9+
* `initializeAdminApp()` now relies on `firebase-admin` rather than imitating the Admin SDK.

.changeset/config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@firebase/app-types-exp",
1818
"@firebase/functions-exp",
1919
"@firebase/functions-types-exp",
20+
"@firebase/testing",
2021
"firebase-exp",
2122
"@firebase/changelog-generator",
2223
"firebase-size-analysis"
@@ -25,4 +26,4 @@
2526
"onlyUpdatePeerDependentsWhenOutOfRange": true,
2627
"useCalculatedVersionForSnapshots": true
2728
}
28-
}
29+
}

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ packages/auth-types @bojeil-google @avolkovi @samhorlbeck @scottcrossen @fireba
6060

6161
# Testing Code
6262
packages/testing @avolkovi @samhorlbeck @scottcrossen @yuchenshi @firebase/jssdk-global-approvers
63+
packages/rules-unit-testing @avolkovi @samhorlbeck @scottcrossen @yuchenshi @firebase/jssdk-global-approvers
6364

6465
# RxFire Code
6566
packages/rxfire @davideast @jamesdaniels @firebase/jssdk-global-approvers
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

packages/rules-unit-testing/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# @firebase/rules-unit-testing
2+
3+
A set of utilities useful for testing Security Rules with the Realtime Database or Cloud Firestore
4+
emulators.
5+
6+
See:
7+
8+
* [Test your Cloud Firestore Security Rules](https://firebase.google.com/docs/firestore/security/test-rules-emulator)
9+
* [Testing Security Rules with the Realtime Database Emulator](https://firebase.google.com/docs/database/security/test-rules-emulator)
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"emulators": {
3+
"firestore": {
4+
"port": 9003
5+
},
6+
"database": {
7+
"port": 9002
8+
},
9+
"ui": {
10+
"enabled": false
11+
}
12+
}
13+
}

packages/rules-unit-testing/index.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright 2017 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* The testing module does not need to be registered since it should not ever
20+
* come by default. The only way to use the testing module is by explicitly
21+
* creating a dependency on @firebase/rules-unit-testing.
22+
*/
23+
24+
export {
25+
apps,
26+
assertFails,
27+
assertSucceeds,
28+
clearFirestoreData,
29+
database,
30+
firestore,
31+
initializeAdminApp,
32+
initializeTestApp,
33+
loadDatabaseRules,
34+
loadFirestoreRules
35+
} from './src/api';
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "@firebase/rules-unit-testing",
3+
"version": "0.1.0",
4+
"description": "",
5+
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
6+
"main": "dist/index.cjs.js",
7+
"engines": {
8+
"node": "^8.13.0 || >=10.10.0"
9+
},
10+
"files": [
11+
"dist"
12+
],
13+
"scripts": {
14+
"build": "rollup -c",
15+
"build:deps": "lerna run --scope @firebase/rules-unit-testing --include-dependencies build",
16+
"dev": "rollup -c -w",
17+
"test:nyc": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --config ../../config/mocharc.node.js",
18+
"test": "firebase --debug emulators:exec 'yarn test:nyc'",
19+
"test:ci": "node ../../scripts/run_tests_in_ci.js",
20+
"prepare": "yarn build"
21+
},
22+
"license": "Apache-2.0",
23+
"dependencies": {
24+
"firebase": "7.17.2",
25+
"@firebase/logger": "0.2.6",
26+
"@firebase/util": "0.3.0",
27+
"request": "2.88.2"
28+
},
29+
"devDependencies": {
30+
"@google-cloud/firestore": "4.2.0",
31+
"@types/request": "2.48.5",
32+
"firebase-admin": "9.0.0",
33+
"firebase-tools": "8.7.0",
34+
"rollup": "2.23.0",
35+
"rollup-plugin-typescript2": "0.27.1"
36+
},
37+
"peerDependencies": {
38+
"@google-cloud/firestore": "^4.2.0",
39+
"firebase-admin": "^9.0.0"
40+
},
41+
"repository": {
42+
"directory": "packages/rules-unit-testing",
43+
"type": "git",
44+
"url": "https://github.com/firebase/firebase-js-sdk.git"
45+
},
46+
"typings": "dist/index.d.ts",
47+
"bugs": {
48+
"url": "https://github.com/firebase/firebase-js-sdk/issues"
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @license
3+
* Copyright 2018 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import typescriptPlugin from 'rollup-plugin-typescript2';
19+
import pkg from './package.json';
20+
import typescript from 'typescript';
21+
22+
const plugins = [
23+
typescriptPlugin({
24+
typescript
25+
})
26+
];
27+
28+
const deps = Object.keys(
29+
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
30+
);
31+
32+
export default {
33+
input: 'index.ts',
34+
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
35+
plugins: [...plugins],
36+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
37+
};

0 commit comments

Comments
 (0)