-
Notifications
You must be signed in to change notification settings - Fork 107
Finish Translating Testing Environments #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Aissaoui-Ahmed
merged 5 commits into
reactjs:master
from
mohamedsgap:translate-testing-env
Nov 30, 2019
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
840510b
translate first part of testing-envs
mohamedsgap f84d6e2
finish translating testing envs
mohamedsgap 9ca4bb8
improve testing envs translate
mohamedsgap 6818581
modify testing envs translate
mohamedsgap 5cdf49b
remove spaces & improve translation
mohamedsgap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,60 @@ | ||
--- | ||
id: testing-environments | ||
title: Testing Environments | ||
title: بيئات الاختبار | ||
permalink: docs/testing-environments.html | ||
prev: testing-recipes.html | ||
--- | ||
|
||
<!-- This document is intended for folks who are comfortable with JavaScript, and have probably written tests with it. It acts as a reference for the differences in testing environments for React components, and how those differences affect the tests that they write. This document also assumes a slant towards web-based react-dom components, but has notes for other renderers. --> | ||
|
||
This document goes through the factors that can affect your environment and recommendations for some scenarios. | ||
يتناول هذا المستند العوامل التي يمكن أن تؤثر على بيئتك والتوصيات المتعلقة ببعض السيناريوهات. | ||
|
||
### Test runners {#test-runners} | ||
|
||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Test runners like [Jest](https://jestjs.io/), [mocha](https://mochajs.org/), [ava](https://github.com/avajs/ava) let you write test suites as regular JavaScript, and run them as part of your development process. Additionally, test suites are run as part of continuous integration. | ||
### منفذي الاختبار {#test-runners} | ||
|
||
- Jest is widely compatible with React projects, supporting features like mocked [modules](#mocking-modules) and [timers](#mocking-timers), and [`jsdom`](#mocking-a-rendering-surface) support. **If you use Create React App, [Jest is already included out of the box](https://facebook.github.io/create-react-app/docs/running-tests) with useful defaults.** | ||
- Libraries like [mocha](https://mochajs.org/#running-mocha-in-the-browser) work well in real browser environments, and could help for tests that explicitly need it. | ||
- End-to-end tests are used for testing longer flows across multiple pages, and require a [different setup](#end-to-end-tests-aka-e2e-tests). | ||
يتيح لك منفذى الاختبار مثل [Jest](https://jestjs.io/), [mocha](https://mochajs.org/), [ava](https://github.com/avajs/ava) كتابة مجموعات اختبار على هيئه JavaScript و تشغيلها كجزء من عملية التطوير الخاصة بك. بالاضافة الى ذلك يتم تشغبل مجموعات الاختبار كجزء من التكامل المستمر. | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Mocking a rendering surface {#mocking-a-rendering-surface} | ||
- Jest متوافق على نطاق واسع مع مشاريع React, و دعم مميزات جديده مثل [الوحدات النمطية ](#moking-modules)و [العداد](#moking-timers) و دعم [`jsdom`](#mocking-a-rendering-surface`). **اذا كنت تستخدم Create React App اذن [Jest موجود بالفعل](https://facebook.github.io/create-react-app/docs/running-tests) مع افتراضات مفيده**. | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- المكتبات مثل [mocha](https://mochajs.org/#running-mocha-in-the-browser) تعمل بشكل جيد في بيئات المتصفح الحقيقي ، ويمكن أن تساعد في الاختبارات التي تحتاجها بشكل صريح. | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- تُستخدم الاختبارات من طرف إلى طرف لاختبار تدفقات أطول عبر عدة صفحات ، وتتطلب [إعداد مختلف](#end-to-end-tests-aka-e2e-tests). | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Tests often run in an environment without access to a real rendering surface like a browser. For these environments, we recommend simulating a browser with [`jsdom`](https://github.com/jsdom/jsdom), a lightweight browser implementation that runs inside Node.js. | ||
### محاكاة سطح التصيير {#mocking-a-rendering-surface} | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
In most cases, jsdom behaves like a regular browser would, but doesn't have features like [layout and navigation](https://github.com/jsdom/jsdom#unimplemented-parts-of-the-web-platform). This is still useful for most web-based component tests, since it runs quicker than having to start up a browser for each test. It also runs in the same process as your tests, so you can write code to examine and assert on the rendered DOM. | ||
تعمل الاختبارات غالبًا في بيئة دون الوصول إلى سطح التصيير الحقيقي مثل المستعرض. بالنسبة لهذه البيئات ، نوصي بمحاكاة مستعرض باستخدام [`jsdom`](https://github.com/jsdom/jsdom) ، وهو تطبيق متصفح خفيف الوزن يعمل داخل Node.js. | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Just like in a real browser, jsdom lets us model user interactions; tests can dispatch events on DOM nodes, and then observe and assert on the side effects of these actions [<small>(example)</small>](/docs/testing-recipes.html#events). | ||
في معظم الحالات ، يتصرف jsdom كالمتصفح العادي ، لكن ليس به ميزات مثل [layout and navigation ](https://github.com/jsdom/jsdom#unimplemented-parts-of-the-web-platform). لا يزال هذا مفيدًا لمعظم اختبارات المكونات المستندة إلى الويب ، لأنه يعمل بشكل أسرع من الاضطرار إلى بدء تشغيل مستعرض لكل اختبار. يتم تشغيله أيضًا في نفس عملية الاختبارات الخاصة بك ، حتى تتمكن من كتابة التعليمات البرمجية لفحصها وتأكيدها على DOM. | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
A large portion of UI tests can be written with the above setup: using Jest as a test runner, rendered to jsdom, with user interactions specified as sequences of browser events, powered by the `act()` helper [<small>(example)</small>](/docs/testing-recipes.html). For example, a lot of React's own tests are written with this combination. | ||
تمامًا كما في المتصفح الحقيقي ، تتيح لنا jsdom تصميم تفاعلات المستخدم ؛ يمكن للاختبارات إرسال الأحداث على عقد DOM ، ثم مراقبة الآثار الجانبية لهذه الإجراءات والتأكيد عليها [<small>(مثال)</small>](/docs/testing-recipes.html#events). | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
If you're writing a library that tests mostly browser-specific behavior, and requires native browser behavior like layout or real inputs, you could use a framework like [mocha.](https://mochajs.org/) | ||
|
||
In an environment where you _can't_ simulate a DOM (e.g. testing React Native components on Node.js), you could use [event simulation helpers](https://reactjs.org/docs/test-utils.html#simulate) to simulate interactions with elements. Alternately, you could use the `fireEvent` helper from [`@testing-library/react-native`](https://testing-library.com/docs/native-testing-library). | ||
يمكن كتابة جزء كبير من اختبارات واجهة المستخدم باستخدام الإعداد أعلاه: استخدام Jest كمنفذ للاختبار ، يتم تصييره إلى jsdom ، مع تفاعلات المستخدم المحددة كسلسلة من أحداث المتصفح ، مدعومًا بـ `act ()` helper [<small>(مثال)</small>](/docs/testing-recipes.html). على سبيل المثال ، تتم كتابة الكثير من اختبارات React الخاصة مع هذه المجموعة. | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Frameworks like [Cypress](https://www.cypress.io/), [puppeteer](https://github.com/GoogleChrome/puppeteer) and [webdriver](https://www.seleniumhq.org/projects/webdriver/) are useful for running [end-to-end tests](#end-to-end-tests-aka-e2e-tests). | ||
إذا كنت تكتب مكتبة تختبر في الغالب السلوك الخاص بالمتصفح ، وتتطلب سلوك المستعرض الأصلي مثل التخطيط أو المدخلات الحقيقية ، يمكنك استخدام إطار عمل مثل [mocha.](https://mochajs.org/) | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Mocking functions {#mocking-functions} | ||
في بيئة لا يمكنك فيها محاكاة DOM (على سبيل المثال ، اختبار مكونات React Native على Node.js) ، يمكنك استخدام [مساعدي محاكاة الأحداث](https://reactjs.org/docs/test-utils.html#simulate) لمحاكاة التفاعلات مع العناصر. بالتناوب ، يمكنك استخدام "fireEvent" المساعد من [`@ testing-library / react-native`](https://testing-library.com/docs/native-testing-library). | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
When writing tests, we'd like to mock out the parts of our code that don't have equivalents inside our testing environment (e.g. checking `navigator.onLine` status inside Node.js). Tests could also spy on some functions, and observe how other parts of the test interact with them. It is then useful to be able to selectively mock these functions with test-friendly versions. | ||
اطارات العمل مثل [Cypress](https://www.cypress.io/) و [puppeteer](https://github.com/GoogleChrome/puppeteer) و [webdriver](https://www.seleniumhq.org/projects / webdriver /) مفيدة لتشغيل [end-to-end test ](#end-to-end-tests-aka-e2e-tests). | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This is especially useful for data fetching. It is usually preferable to use "fake" data for tests to avoid the slowness and flakiness due to fetching from real API endpoints [<small>(example)</small>](/docs/testing-recipes.html#data-fetching). This helps make the tests predictable. Libraries like [Jest](https://jestjs.io/) and [sinon](https://sinonjs.org/), among others, support mocked functions. For end-to-end tests, mocking network can be more difficult, but you might also want to test the real API endpoints in them anyway. | ||
### محاكاة الدوال {#mocking-functions} | ||
|
||
### Mocking modules {#mocking-modules} | ||
عند كتابة الاختبارات ، نود أن نحاكى الكود الخاص بنا الذى لا يحتوى على مكافئ له فى بيئة الاختبار الخاصة بنا (على سبيل المثال التحقق من حالة `navigator.onLin` داخل Node.js). يمكن للاختبارات أيضًا التجسس على بعض الوظائف ، ومراقبة كيفية تفاعل أجزاء أخرى من الاختبار معها. من المفيد عندئذ أن تكون قادرًا على محاكاة هذه الدوال باصدارات سهلة الاستخدام بشكل الانتقائى. | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Some components have dependencies for modules that may not work well in test environments, or aren't essential to our tests. It can be useful to selectively mock these modules out with suitable replacements [<small>(example)</small>](/docs/testing-recipes.html#mocking-modules). | ||
هذا مفيد بشكل خاص لجلب البيانات. من المفضل عادة استخدام البيانات "المزيفة" للاختبارات لتجنب البطء والضعف بسبب جلب نقاط نهاية API الحقيقية [<small>(مثال) </small>](/docs/testing-recipes.html#data-fetching ). هذا يساعد على جعل الاختبارات يمكن التنبؤ بها. المكتبات مثل [Jest](https://jestjs.io/) و [sinon](https://sinonjs.org/)، من بين أمور أخرى ، تدعم محاكاه الدوال. بالنسبة للاختبارات الشاملة ، يمكن أن تكون محاكاة الشبكة أكثر صعوبة ، ولكن قد ترغب أيضًا في اختبار نقاط النهاية الحقيقية لواجهة برمجة التطبيقات فيها. | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
On Node.js, runners like Jest [support mocking modules](https://jestjs.io/docs/en/manual-mocks). You could also use libraries like [`mock-require`](https://www.npmjs.com/package/mock-require). | ||
### محاكاه الوحدات {#mocking-modules} | ||
|
||
### Mocking timers {#mocking-timers} | ||
تحتوي بعض المكونات على تبعيات للوحدات النمطية التي قد لا تعمل بشكل جيد في بيئات الاختبار ، أو ليست ضرورية لاختباراتنا. قد يكون من المفيد الاستغناء عن هذه الوحدات بشكل انتقائي مع بدائل مناسبة [<small>(مثال)</small>](/docs/testing-recipes.html#mocking-modules). | ||
|
||
Components might be using time-based functions like `setTimeout`, `setInterval`, or `Date.now`. In testing environments, it can be helpful to mock these functions out with replacements that let you manually "advance" time. This is great for making sure your tests run fast! Tests that are dependent on timers would still resolve in order, but quicker [<small>(example)</small>](/docs/testing-recipes.html#timers). Most frameworks, including [Jest](https://jestjs.io/docs/en/timer-mocks), [sinon](https://sinonjs.org/releases/v7.3.2/fake-timers/) and [lolex](https://github.com/sinonjs/lolex), let you mock timers in your tests. | ||
على Node.js ، يقوم منفذى الاختبارات مثل Jest [بدعم محاكاة الوحدات](https://jestjs.io/docs/en/manual-mocks). يمكنك أيضًا استخدام مكتبات مثل [`mock-require`](https://www.npmjs.com/package/mock-require). | ||
|
||
Sometimes, you may not want to mock timers. For example, maybe you're testing an animation, or interacting with an endpoint that's sensitive to timing (like an API rate limiter). Libraries with timer mocks let you enable and disable them on a per test/suite basis, so you can explicitly choose how these tests would run. | ||
### محاكاة العداد {#mocking-timers} | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### End-to-end tests {#end-to-end-tests-aka-e2e-tests} | ||
قد تستخدم المكونات وظائف تستند إلى الوقت مثل `setTimeout` أو` setInterval` أو `Date.now`. في بيئات الاختبار ، قد يكون من المفيد الاستغناء عن هذه الوظائف مع البدائل التي تتيح لك "التقدم" يدويًا. هذا شيء عظيم للتأكد من أن اختباراتك تعمل بسرعة! الاختبارات التي تعتمد على العداد ستظل قائمة بالترتيب ، ولكن أسرع [<small>(مثال)</small>](/docs/testing-recipes.html#timers). معظم اطارات العمل ، بما في ذلك [Jest](https://jestjs.io/docs/en/timer-mocks) ، [sinon](https://sinonjs.org/releases/v7.3.2/fake-timers/) و [lolex](https://github.com/sinonjs/lolex) ، تتيح لك محاكاة العداد في اختباراتك. | ||
|
||
End-to-end tests are useful for testing longer workflows, especially when they're critical to your business (such as payments or signups). For these tests, you'd probably want to test both how a real browser renders the whole app, fetches data from the real API endpoints, uses sessions and cookies, navigates between different links. You might also likely want to make assertions not just on the DOM state, but on the backing data as well (e.g. to verify whether the updates have been persisted to the database). | ||
في بعض الأحيان ، قد لا ترغب في محاكاة العداد. على سبيل المثال ، ربما تقوم باختبار رسم متحرك ، أو تتفاعل مع نقطة نهاية حساسة للتوقيت (like an API rate limiter). تتيح لك المكتبات التي بها محاكاه العداد تمكينها وتعطيلها على أساس كل اختبار / مجموعة ، بحيث يمكنك اختيار كيفية تشغيل هذه الاختبارات بشكل صريح. | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
In this scenario, you would use a framework like [Cypress](https://www.cypress.io/) or a library like [puppeteer](https://github.com/GoogleChrome/puppeteer) so you can navigate between multiple routes and assert on side effects not just in the browser, but potentially on the backend as well. | ||
### اختبارات طرف الى طرف {#end-to-end-tests-aka-e2e-tests} | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
تعد اختبارات طرف الى طرف مفيدة لاختبار سير عمل أطول ، خاصةً عندما تكون مهمة لنشاطك التجاري (مثل المدفوعات أو الاشتراكات). بالنسبة لهذه الاختبارات ، قد ترغب في اختبار كلٍّ من كيفية عرض المتصفح الحقيقي للتطبيق بأكمله ، وجلب البيانات من نقاط النهاية الحقيقية لواجهة برمجة التطبيقات ، واستخدام الجلسات وملفات تعريف الارتباط ، والتنقل بين الروابط المختلفة. قد ترغب أيضًا في تقديم تأكيدات ليس فقط في حالة DOM ، ولكن أيضًا على بيانات النسخ الاحتياطي (على سبيل المثال للتحقق من استمرار التحديثات في قاعدة البيانات). | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
في هذا السيناريو ، يمكنك استخدام إطار عمل مثل [Cypress](https://www.cypress.io/) أو مكتبة مثل [puppeteer](https://github.com/GoogleChrome/puppeteer) حتى تتمكن من التنقل بين طرق متعددة والتأكيد على الآثار الجانبية ليس فقط في المتصفح ، ولكن يحتمل أن يكون على الواجهة الخلفية أيضًا. | ||
3imed-jaberi marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.