hoares

分类

最新留言

链接

RSS

RSS Link
E4 RCP, what can be injected
Keyboard shortcuts in bash

Globing in JsTestDriver

hoares posted @ 2012年11月30日 15:12 in 未分类 with tags javascript , 1278 阅读

Suppose the layout of the js files is like this:

src

|- code.js

|- a_sub_folder

|- code.js

test

|-test.js

In the jstd conf file, if we want to load all the js files in "src" folder and jstd 1.3.5 is used, we can use:

load:

  - src/*.js

Note that, it will not only load all the js files that are under "src" folder directly but also those in the "a_sub_folder". src/**/*.js can also be used and the result would be the same.

The tricky part here is when you use following pattern:

load:

  - src/code.js

We would expected to load code.js under src folder but not code.js under src/a_sub_folder/code.js. Actually both code.js file will be loaded. Since the files are loaded in alphabetic order, src/a_sub_folder/code.js will be loaded first and the src/code.js. (Note "a_sub_folder" starts with "a" and "code.js" start with "c").

It seems there is no way that you can load "src/code.js" only. If "src/a_sub_folder/code.js" is depends on "src/code.js", there will be errors when running test. That would be a big problem if you're working with legacy code and you don't want to make a restructure for jstd support.

This is due to the PathResovler class when expanding globs

private String[] expandGlob(String filePath, String fileNamePattern, File dir) {
	FilenameFilter fileFilter = new GlobFilenameFilter(fileNamePattern,
			GlobCompiler.DEFAULT_MASK | GlobCompiler.CASE_INSENSITIVE_MASK);
	String[] filteredFiles = expandDeepDirectoryGlobPaths(dir, fileFilter, "").toArray(new String[0]);

	if (filteredFiles == null || filteredFiles.length == 0) {
		return null;
	}
	Arrays.sort(filteredFiles, String.CASE_INSENSITIVE_ORDER);
	return filteredFiles;
}

Following test I added in PathResovlerTest confirms this assertion

public void testDoGlobingEvenIfNoWildCardCharacter() throws Exception {
    File dir = tmpDirs.iterator().next();
    File codeDir = createTmpSubDir("code", dir);
    createTmpFile(dir, "code.js");
    createTmpFile(codeDir, "code.js");

    String configFile = "load:\n - code.js";
    ByteArrayInputStream bais = new ByteArrayInputStream(configFile.getBytes());
    ConfigurationParser parser = new YamlParser();

    Configuration config = parser.parse(new InputStreamReader(bais), null).resolvePaths(
            new PathResolver(tmpDirs, Collections.<FileParsePostProcessor>emptySet(), new DisplayPathSanitizer()), createFlags());
    Set<FileInfo> files = config.getFilesList();
    List<FileInfo> listFiles = new ArrayList<FileInfo>(files);

    assertEquals(2, files.size());
    assertTrue(listFiles.get(0).getFilePath().replace(File.separatorChar, '/').endsWith("code.js"));
    assertTrue(listFiles.get(1).getFilePath().replace(File.separatorChar, '/').endsWith("code/code.js"));
}

 

Avatar_small
Lachlan Bleakley 说:
2019年6月03日 19:22

The test driving is the driving for test the ability of the system by the working and making the habits cool and fictional. The happy coding is presenting the https://topamericanwriters.com/bestessays-com-review/ where we can get the layout of the files of our choice.

Avatar_small
DanielRodger 说:
2019年7月24日 16:30

The idea behind test settings is to isolate the language structure you use to compose an experiment from the apparatuses that run and envision aftereffects of these tests. They additionally empower us to give connectors for other test structures, for example, in buster-jstestdriver. Buy Essay Online | EssayEmpire

Avatar_small
Emma 说:
2022年11月17日 19:43

It was so good to see the screenshot of the program shared here. Everything regarding Globing in JsTestDriver is mentioned CBD And Driving here step by step. If you have any doubts regarding that, you can contact us here for further updates. You will get answers from experts over here. Keep sharing more updates on that.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter