Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

feat: support async/await in jest tests (#105) #138

Merged
merged 2 commits into from
Jul 2, 2019

Conversation

thektan
Copy link
Member

@thektan thektan commented Jun 27, 2019

I created a babel.test.json to separate the babel configurations between the test and build scripts. I didn't use the const isTest = api.env('test'); in babel.config.js example from the jest docs so we could continue to use the babelMerge function in deepMerge.js as is.

But I'm also not sure what the implications would be if we only applied the following to the current babel.json instead of creating a separate babel.test.json.

{
	"presets": [
		[
			"@babel/preset-env",
			{
				"targets": {
					"node": "current"
				}
			}
		]
	],
...

*Also as an additional note, currently the only place that will have async/await in tests is still in a dev branch yet to be merged in master. https://github.com/thektan/liferay-portal/blob/LPS-96356-fix-frontend-tests/modules/apps/portal-search/portal-search-ranking-web/test/js/components/ResultsRankingForm.js

@wincent wincent changed the title Support async/await in jest tests (#105) feat: support async/await in jest tests (#105) Jul 1, 2019
@wincent
Copy link
Contributor

wincent commented Jul 1, 2019

Thanks @thektan. Would it be possible to do this without creating babel.test.json using the "overrides" feature? Something like:

diff --git a/packages/liferay-npm-scripts/src/config/babel.json b/packages/liferay-npm-scripts/src/config/babel.json
index 94c14b0..64eb93a 100644
--- a/packages/liferay-npm-scripts/src/config/babel.json
+++ b/packages/liferay-npm-scripts/src/config/babel.json
@@ -3,5 +3,16 @@
 	"plugins": [
 		"@babel/proposal-class-properties",
 		"@babel/proposal-object-rest-spread"
+	],
+	"overrides": [
+		{
+			"test": "**/test/*.js",
+			"presets": [
+				"env",
+				{
+					"targets": {"node": "current"}
+				}
+			]
+		}
 	]
 }

(Untested — the "test" glob might not be exactly right — but that's the basic idea.)

@thektan
Copy link
Member Author

thektan commented Jul 1, 2019

@wincent Neat! I used the same glob used in the jest configs.

@wincent
Copy link
Contributor

wincent commented Jul 2, 2019

Nice! Glad it ended up being a minimal change. Let's merge this and we'll see if it breaks all the JS tests in liferay-portal. 😂

thektan and others added 2 commits July 2, 2019 11:36
Just to make sure we don't start using features that aren't actually
supported by the version of NodeJS that we actually use in
liferay-portal (currently, v10.15.1).
@wincent wincent merged commit 4dbf731 into liferay:master Jul 2, 2019
@wincent
Copy link
Contributor

wincent commented Jul 2, 2019

@thektan: I rebased your branch on top of current "master" and added one tweak on top (b12b6fc) just to make sure we don't end up depending on untranspiled features that don't exist in liferay-portal's version of Node (v10.15.1) yet. It has async/await, for example, but not public class fields (silly example, I know, as we're unlikely to use those in a test, but you get the idea).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants