As per the vue-sweetalert2 doc, in my main.js, I import and use the plugin:
import VueSweetalert2 from "vue-sweetalert2";
Vue.use(VueSweetalert2);
In my component, ContactForm.vue, I can use:
this.$swal(...)
However, when I test:unit this component, I need to add the import and Vue.use()
import VueSweetalert2 from "vue-sweetalert2";
Vue.use(VueSweetalert2);
and I get an error:
$ vue-cli-service test:unit ContactForm.spec.js
FAIL tests/unit/ContactForm.spec.js
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/Users/yves/Developments/WIP/VUE.JS-cli-3/3-chocha-home-content/chocha/node_modules/vue-sweetalert2/src/index.js:2
import swal from 'sweetalert2/dist/sweetalert2.min.js';
^^^^^^
SyntaxError: Unexpected token import
What could be wrong?
UPDATE
the vue-sweetalert2/src/index.js, line 2 faulty line, is:
// #ts-check
import swal from 'sweetalert2/dist/sweetalert2.min.js';
the developer of this wrapper added an index.d.ts fie
import Vue, { PluginObject, PluginFunction } from 'vue';
import * as swal from 'sweetalert2';
...
but it seems not to be taken in account.
SOLVED ...
I added a transformIgnorePatterns in my jest config in package.json
"jest": {
....
"transformIgnorePatterns": [
"/node_modules/(?!vue-sweetalert2).+\\.js$"
],
....
}
Related
I am attempting to add the cypress-angular-unit-test plugin to Cypress.
However, following the instructions provided on the related GitHub page I am getting the following error:
The plugins file is missing or invalid.
/MyProjectName/cypress/plugins/index.js:1
import * as cypressTypeScriptPreprocessor from 'cy-ts-preprocessor';
^^^^^^
SyntaxError: Cannot use import statement outside a module
Again, as instructed, I have added the following to support/index.js
// core-js 3.*
require('core-js/es/reflect');
// core-js 2.*
require('core-js/es7/reflect');
require('cypress-angular-unit-test/support');
And the following to plugins/index.js
import * as cypressTypeScriptPreprocessor from 'cy-ts-preprocessor';
module.exports = (on, config) => {
on('file:preprocessor', cypressTypeScriptPreprocessor);
require('#cypress/code-coverage/task')(on, config);
return config;
};
I've also added the related helper.js and cy-ts-preprocessor.js file to the plugins folder.
I've also added the necessary config to cypress.json
"experimentalComponentTesting": true,
I've even tried adding types/node by adding a tsconfig.json to the cypress folder like so:
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node"],
"experimentalDecorators": true
},
"include": [
"**/*.ts"
]
}
Changing the target and/or lib values to es6 has no effect.
Changing the import to a require yields a different error which, even if it did work, seems like a hacky solution for some detail I am missing.
¯\_(ツ)_/¯
Not exactly an answer but at least a work around.
Start fresh or uninstall Cypress and cypress-angular-unit-test
Follow the instructions for Nx Cypress install found on here
Go back to cypress-angular-unit-test instructions and ignore this part:
Configure cypress/plugins/index.js to transpile Angular code.
import * as cypressTypeScriptPreprocessor from './cy-ts-preprocessor';
module.exports = (on, config) => {
on('file:preprocessor', cypressTypeScriptPreprocessor);
return config;
};
The file cy-ts-preprocessor is here
I installed browser-image-compression which, as part of its functionality, creates a Worker. Now when I run jest tests, I get the following error:
Test suite failed to run
ReferenceError: Worker is not defined
There are no tests connected to the function which uses browser-image-compression.
The scripts section in package.json has the following two lines
"test": "react-scripts test",
"test:ci": "cross-env CI=true react-scripts test"
Oh, and I have a file for setting up tests. Should I mock Worker in here?
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import '#domain/yup';
configure({
adapter: new Adapter()
});
global.fetch = require('jest-fetch-mock');
Late in responding to this but it could help others - but following this comment helped me with this issue.
If you add the following to its own file - I have mine within the same dir as the setupTests file named workerMock.js:
export default class Worker {
constructor(stringUrl) {
this.url = stringUrl;
this.onmessage = () => {};
}
postMessage(msg) {
this.onmessage(msg);
}
}
Then import that Worker file into your test setup file and add window.Worker = Worker. Your setup file may look like:
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import '#domain/yup';
import Worker from 'path-to-your-worker-file-above';
configure({
adapter: new Adapter()
});
global.fetch = require('jest-fetch-mock');
window.Worker = Worker;
Hope this helps
A better solution is that updating 'browser-image-compression' package to the latest version , this helped me .
I am getting following error while running flutter unit test.
00:05 +1: ...
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/Refund_test.dart
Shell: [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: error:
import of dart:mirrors with
--enable-mirrors=false Shell: [ERROR:flutter/shell/common/engine.cc(175)] Could not prepare to run
the isolate. Shell: [ERROR:flutter/shell/common/engine.cc(122)] Engine
not prepare and launch isolate. Shell:
[ERROR:flutter/shell/testing/tester_main.cc(199)] Could not launch the
engine with configuration. 00:05 +1 -1: loading
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/Refund_test.dart
[E] Failed to load
"/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/Refund_test.dart":
Shell subprocess cleanly reported an error before connecting to test
harness. Check the logs above for an error message. Test:
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/Refund_test.dart
Shell:
/home/kazekage/Developement/flutter_linux_v1.2.1-stable/flutter/bin/cache/artifacts/engine/linux-x64/flutter_tester
Shell: [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: error: import of dart:mirrors with
--enable-mirrors=false Shell: [ERROR:flutter/shell/common/engine.cc(175)] Could not prepare to run
the isolate. Shell: [ERROR:flutter/shell/common/engine.cc(122)] Engine
not prepare and launch isolate. Shell:
[ERROR:flutter/shell/testing/tester_main.cc(199)] Could not launch the
engine with configuration. 00:05 +1 -2: loading
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/LineItem_test.dart
[E] Failed to load
"/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/LineItem_test.dart":
Shell subprocess cleanly reported an error before connecting to test
harness. Check the logs above for an error message. Test:
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/LineItem_test.dart
Shell:
/home/kazekage/Developement/flutter_linux_v1.2.1-stable/flutter/bin/cache/artifacts/engine/linux-x64/flutter_tester
Shell: [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: error: import of dart:mirrors with
--enable-mirrors=false Shell: [ERROR:flutter/shell/common/engine.cc(175)] Could not prepare to run
the isolate. Shell: [ERROR:flutter/shell/common/engine.cc(122)] Engine
not prepare and launch isolate. Shell:
[ERROR:flutter/shell/testing/tester_main.cc(199)] Could not launch the
engine with configuration. 00:06 +1 -3: loading
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/ShippingLine_test.dart
[E] Failed to load
"/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/ShippingLine_test.dart":
Shell subprocess cleanly reported an error before connecting to test
harness. Check the logs above for an error message. Test:
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/ShippingLine_test.dart
Shell:
/home/kazekage/Developement/flutter_linux_v1.2.1-stable/flutter/bin/cache/artifacts/engine/linux-x64/flutter_tester
pubsec.yml
name: flutter_woocommerce
description: A new Flutter package project.
version: 0.0.1
author:
homepage:
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
dio: ^2.1.6
built_value: ^6.6.0
built_value_generator: ^6.6.0
built_collection: ^4.2.2
dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^4.0.0
build_runner: ^1.5.0
source_gen: ^0.9.4+2
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.io/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.io/custom-fonts/#from-packages
flutter doctor
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Android Studio (version 3.4)
[!] IntelliJ IDEA Ultimate Edition (version 2018.3)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.35.0)
[!] Connected device
! No devices available
! Doctor found issues in 2 categories.
Tag.dart
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:flutter_woocommerce/model/util/Link.dart';
part 'Tag.g.dart';
abstract class Tag implements Built<Tag, TagBuilder> {
static Serializer<Tag> get serializer => _$tagSerializer;
int get id;
String get name;
String get slug;
#nullable
String get description;
#nullable
int get count;
#nullable
#BuiltValueField(wireName: '_links')
Link get links;
Tag._();
factory Tag([updates(TagBuilder b)]) = _$Tag;
}
Tag_test.dart
import 'package:flutter_test/flutter_test.dart';
import 'dart:convert';
import 'package:built_collection/built_collection.dart';
import 'package:flutter_woocommerce/test_strings.dart';
import 'package:flutter_woocommerce/model/Serializers.dart';
import 'package:flutter_woocommerce/model/Tag.dart';
import 'package:flutter_woocommerce/model/util/Link.dart';
void main() {
final parsedJson = json.decode(TestStrings.TAG_JSON);
Tag tag = serializers.deserializeWith(Tag.serializer, parsedJson);
test('id', () {
expect(tag.id, 32);
});
test('name', () {
expect(tag.name, 'Telephone');
});
test('slug', () {
expect(tag.slug, 'telephone');
});
test('description', () {
expect(tag.description, '');
});
test('count', (){
expect(tag.count, 0);
});
test('_links is Link Object', () {
expect(tag.links, isInstanceOf<Link>());
});
test('_links > self is href[]', () {
expect(tag.links.self, isInstanceOf<BuiltList<Href>>());
});
test('_links > collection is href[]', () {
expect(tag.links.collection, isInstanceOf<BuiltList<Href>>());
});
test('_links > collection > href value', () {
expect(tag.links.collection.first.href, 'http://paathsala-wp.test/wp-json/wc/v2/products/tags');
});
}
The problem is that you're trying to use reflection (dart:mirror), which is not possible with Flutter because:
"Since reflection makes all code implicitly used by default, it interferes with tree shaking." Source
I believe it is related with the JSON serialization provided by the built_value_generator dart package.
It seems I have imported a wrong library in one of my model class. Once I removed the library
import 'package:built_collection/built_collection.dart';
All the tests are passing.
I am trying to configure Jenkins to build my Selenium Webdriver Python code.
When i click Build Now it fails
The Console output shows the following:
Building in workspace C:\Program Files\Jenkins\workspace\ClearCore
[ClearCore] $ cmd /c call C:\Windows\TEMP\hudson6133135491793466847.bat
C:\Program Files\Jenkins\workspace\ClearCore>copy E:\RL Fusion\projects\Jenkins sample\ClearCore501\TestCases\*.py
The system cannot find the file specified.
C:\Program Files\Jenkins\workspace\ClearCore>python smoketests.py
python: can't open file 'smoketests.py': [Errno 2] No such file or directory
C:\Program Files\Jenkins\workspace\ClearCore>exit 2
Build step 'Execute Windows batch command' marked build as failure
Recording test results
ERROR: Publisher 'Publish JUnit test result report' failed: No test report files were found. Configuration error?
Finished: FAILURE
In PyCharm i have a smoketests.py file as follows:
import unittest
from xmlrunner import xmlrunner
from TestCases.LoginPage_TestCase import LoginPage_TestCase
from TestCases.AdministrationPage_TestCase import AdministrationPage_TestCase
from TestCases.DataConfigurationPage_TestCase import DataConfigurationPage_TestCase
login_tests = unittest.TestLoader().loadTestsFromTestCase(LoginPage_TestCase)
admin_tests = unittest.TestLoader().loadTestsFromTestCase(AdministrationPage_TestCase)
dataconf_tests = unittest.TestLoader().loadTestsFromTestCase(DataConfigurationPage_TestCase)
smoke_tests = unittest.TestSuite([login_tests, admin_tests, dataconf_tests])
xmlrunner.XMLTestRunner(verbosity=2, output='test-reports').run(smoke_tests)
I have a test_HTMLRunner.py as follows:
import unittest
import HTMLTestRunner
import os
from TestCases.LoginPage_TestCase import LoginPage_TestCase
from TestCases.AdministrationPage_TestCase import AdministrationPage_TestCase
from TestCases.DataConfigurationPage_TestCase import DataConfigurationPage_TestCase
# get the directory path to output report file
result_dir = os.getcwd()
login_tests = unittest.TestLoader().loadTestsFromTestCase(LoginPage_TestCase)
admin_tests = unittest.TestLoader().loadTestsFromTestCase(AdministrationPage_TestCase)
dataconf_tests = unittest.TestLoader().loadTestsFromTestCase(DataConfigurationPage_TestCase)
smoke_tests = unittest.TestSuite([login_tests, admin_tests, dataconf_tests])
# open the report file
outfile = open(result_dir + "\TestReport.html", "w")
# configure HTMLTestRunner options
runner = HTMLTestRunner.HTMLTestRunner(stream=outfile,
title='Test Report',
description='LADEMO create a basic project test')
# run the suite using HTMLTestRunner
runner.run(smoke_tests)
I have a suite.py as follows:
import sys
import unittest
import HTMLTestRunner
import os
import unittest
import AdministrationPage_TestCase
import LoginPage_TestCase
import DataConfigurationPage_TestCase
class Test_Suite(unittest.TestCase):
def test_main(self):
# suite of TestCases
self.suite = unittest.TestSuite()
self.suite.addTests([
unittest.defaultTestLoader.loadTestsFromTestCase(LoginPage_TestCase.LoginPage_TestCase),
unittest.defaultTestLoader.loadTestsFromTestCase(AdministrationPage_TestCase.AdministrationPage_TestCase),
unittest.defaultTestLoader.loadTestsFromTestCase(DataConfigurationPage_TestCase.DataConfigurationPage_TestCase),
])
runner = unittest.TextTestRunner()
runner.run (self.suite)
import unittest
if __name__ == "__main__":
unittest.main()
In Jenkins I have configured the following:
From the section Build, Execute Windows Batch Command
copy E:\RL Fusion\projects\Jenkins sample\ClearCore501\TestCases\*.py
python smoketests.py
From the section Post-Build Actions, Publish JUnit test result report
test_reports/*..xml
Below test_reports/*..xml it shows:
‘test_reports/*..xml’ doesn’t match anything: even ‘test_reports’ doesn’t exist
How do i get this to work please? What am i doing wrong?
Is there any sample demo I could follow and then I can get my setup to work?
Thanks,
Riaz
The problem looks to be in the copy step of you batch file. Notice how it says it cant find the file. Surround the source and destination paths with double quotes so that windows knows your path has spaces in it.
It also appears the copy operation doesn't have a destination specified. You should may want to specify that too. Although apparently that isn't a requirement, as I just found out :).
Once the copy operation succeeds, check the workspace directory to see if the file(s) you expect are present.
Alternatively, you can tell the Jenkins job to use a custom workspace, the directory where your tests live. With this configuration you don't even have to worry about copying files.
Here's how:
In the job config in Jenkins, open the Advanced Project Options and select use custom workspace and set the directory to E:\RL Fusion\projects\Jenkins sample\ClearCore501\TestCases\.
Then the build command can just be python smoketests.py.
I'm migrating a custom made Ember project (I do not use a build system, but actually created my own grunt script). When I run ember-cli-migrate but I'm getting the following error:
Git Move Moving templates/users.hbs to app\templates\users.hbs
Do not know how to import App
Do not know how to import App
Do not know how to import App
Do not know how to import App
Do not know how to import App
Do not know how to import App
Do not know how to import App
Do not know how to import App
assert.js:86
throw new assert.AssertionError({
^
AssertionError: {kind: var, declarations: [object Object], loc: null, type: Vari
ableDeclaration, comments: null} does not match field "init": Expression | null
of type VariableDeclarator
at add (c:\Users\DoryZ\AppData\Roaming\npm\node_modules\ember-cli-migrator\n
ode_modules\recast\node_modules\ast-types\lib\types.js:525:28)
at c:\Users\DoryZ\AppData\Roaming\npm\node_modules\ember-cli-migrator\node_m
odules\recast\node_modules\ast-types\lib\types.js:539:17
at Array.forEach (native)
at Object.defineProperty.value [as variableDeclarator] (c:\Users\DoryZ\AppDa
ta\Roaming\npm\node_modules\ember-cli-migrator\node_modules\recast\node_modules\
ast-types\lib\types.js:538:30)
at Context.MigratorVisitorPrototype.visitAssignmentExpression (c:\Users\Dory
Z\AppData\Roaming\npm\node_modules\ember-cli-migrator\lib\migrator-visitor.js:71
:67)
at Context.invokeVisitorMethod (c:\Users\DoryZ\AppData\Roaming\npm\node_modu
les\ember-cli-migrator\node_modules\recast\node_modules\ast-types\lib\path-visit
or.js:306:43)
at Visitor.PVp.visitWithoutReset (c:\Users\DoryZ\AppData\Roaming\npm\node_mo
dules\ember-cli-migrator\node_modules\recast\node_modules\ast-types\lib\path-vis
itor.js:180:28)
at NodePath.each (c:\Users\DoryZ\AppData\Roaming\npm\node_modules\ember-cli-
migrator\node_modules\recast\node_modules\ast-types\lib\path.js:96:22)
at visitChildren (c:\Users\DoryZ\AppData\Roaming\npm\node_modules\ember-cli-
migrator\node_modules\recast\node_modules\ast-types\lib\path-visitor.js:199:14)
at Visitor.PVp.visitWithoutReset (c:\Users\DoryZ\AppData\Roaming\npm\node_mo
dules\ember-cli-migrator\node_modules\recast\node_modules\ast-types\lib\path-vis
itor.js:188:16)
any help would be appreciatd..