Skip to content

Commit 0226a0e

Browse files
committed
Pause module changes
1 parent 95055a5 commit 0226a0e

5 files changed

Lines changed: 54 additions & 75 deletions

File tree

src/Microsoft.PowerApps.TestEngine/Modules/TestEngineExtensionChecker.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,21 @@ public bool VerifyContainsValidNamespacePowerFxFunctions(TestSettingExtensions s
334334
stream.Position = 0;
335335
ModuleDefinition module = ModuleDefinition.ReadModule(stream);
336336

337+
// Check if PauseModule exists and inspect its IsPreviewNamespaceEnabled property
338+
var pauseModule = module.Types.FirstOrDefault(t => t.Name == "PauseModule");
339+
if (pauseModule != null)
340+
{
341+
// Check if the PauseModule has IsPreviewNamespaceEnabled property
342+
var previewProperty = pauseModule.Properties.FirstOrDefault(p => p.Name == "IsPreviewNamespaceEnabled");
343+
if (previewProperty != null)
344+
{
345+
// If PauseModule has IsPreviewNamespaceEnabled property, enable Preview namespace
346+
// The property's value will be determined at runtime based on YAML settings
347+
settings.AllowPowerFxNamespaces.Add(NAMESPACE_PREVIEW);
348+
Logger?.LogInformation("Auto-enabled Preview namespace due to PauseModule.IsPreviewNamespaceEnabled property.");
349+
}
350+
}
351+
337352
// Get the source code of the assembly as will be used to check Power FX Namespaces
338353
var code = DecompileModuleToCSharp(assembly);
339354

@@ -382,6 +397,13 @@ public bool VerifyContainsValidNamespacePowerFxFunctions(TestSettingExtensions s
382397
// Extension Module Check are based on constructor
383398
if (type.BaseType != null && type.BaseType.Name == "ReflectionFunction")
384399
{
400+
// Special handling for PauseFunction - allow root namespace when PauseModule is present
401+
if (type.Name == "PauseFunction" && pauseModule != null)
402+
{
403+
Logger?.LogInformation($"Allowing PauseFunction in root namespace due to PauseModule presence.");
404+
continue; // Skip namespace validation for PauseFunction
405+
}
406+
385407
var constructors = type.GetConstructors();
386408

387409
if (constructors.Count() == 0)

src/Microsoft.PowerApps.TestEngine/PowerFx/Functions/PauseFunction.cs

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/Microsoft.PowerApps.TestEngine/PowerFx/PowerFxEngine.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public void Setup(TestSettings settings)
102102
powerFxConfig.AddFunction(new AssertNotErrorFunction(Logger));
103103
powerFxConfig.AddFunction(new SetPropertyFunction(_testWebProvider, Logger));
104104
powerFxConfig.AddFunction(new IsMatchFunction(Logger));
105-
powerFxConfig.AddFunction(new PauseFunction(TestInfraFunctions, TestState, Logger));
106105

107106
if (settings != null && settings.ExtensionModules != null && settings.ExtensionModules.Enable)
108107
{
@@ -113,11 +112,7 @@ public void Setup(TestSettings settings)
113112
}
114113
foreach (var module in modules)
115114
{
116-
if (module.GetType().Name.Contains("Pause"))
117-
{
118-
Logger.LogInformation("Skipping pause module as core Pause function is enabled");
119-
continue;
120-
}
115+
// Register all modules including pause module
121116
module.RegisterPowerFxFunction(powerFxConfig, TestInfraFunctions, _testWebProvider, SingleTestInstanceState, TestState, _fileSystem);
122117
}
123118
}

src/testengine.module.pause/PauseFunction.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Microsoft.PowerApps.TestEngine.Config;
66
using Microsoft.PowerApps.TestEngine.TestInfra;
77
using Microsoft.PowerFx;
8-
using Microsoft.PowerFx.Core.Utils;
98
using Microsoft.PowerFx.Types;
109

1110
namespace testengine.module
@@ -18,19 +17,28 @@ public class PauseFunction : ReflectionFunction
1817
private readonly ITestInfraFunctions _testInfraFunctions;
1918
private readonly ITestState _testState;
2019
private readonly ILogger _logger;
20+
private readonly PauseModule _pauseModule;
2121

22-
public PauseFunction(ITestInfraFunctions testInfraFunctions, ITestState testState, ILogger logger)
23-
: base(DPath.Root.Append(new DName("Preview")), "Pause", FormulaType.Blank)
22+
// Register in root (no Preview namespace)
23+
public PauseFunction(ITestInfraFunctions testInfraFunctions, ITestState testState, ILogger logger, PauseModule pauseModule = null)
24+
: base("Pause", FormulaType.Blank)
2425
{
2526
_testInfraFunctions = testInfraFunctions;
2627
_testState = testState;
2728
_logger = logger;
29+
_pauseModule = pauseModule;
2830
}
2931

3032
public BlankValue Execute()
3133
{
32-
_logger.LogInformation("------------------------------\n\n" +
33-
"Executing Pause function.");
34+
_logger.LogInformation("------------------------------\n\nExecuting Pause function.");
35+
36+
// Check if PauseModule's IsPreviewNamespaceEnabled property allows execution
37+
if (_pauseModule != null && !_pauseModule.IsPreviewNamespaceEnabled)
38+
{
39+
_logger.LogInformation("Pause function is disabled - Preview namespace not enabled in PauseModule configuration.");
40+
return FormulaValue.NewBlank();
41+
}
3442

3543
if (!_testState.GetTestSettings().Headless)
3644
{

src/testengine.module.pause/PauseModule.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,31 @@ namespace testengine.module
1616
[Export(typeof(ITestEngineModule))]
1717
public class PauseModule : ITestEngineModule
1818
{
19+
/// <summary>
20+
/// True when YAML testSettings.extensionModules.allowPowerFxNamespaces contains "Preview".
21+
/// Read-only externally; set during registration when TestSettings are available.
22+
/// </summary>
23+
public bool IsPreviewNamespaceEnabled { get; private set; } = false;
24+
1925
public void ExtendBrowserContextOptions(BrowserNewContextOptions options, TestSettings settings)
2026
{
21-
27+
// If called first, try to initialize from provided settings as well
28+
if (settings != null && settings.ExtensionModules != null && settings.ExtensionModules.AllowPowerFxNamespaces != null)
29+
{
30+
IsPreviewNamespaceEnabled = settings.ExtensionModules.AllowPowerFxNamespaces.Contains("Preview");
31+
}
2232
}
2333

2434
public void RegisterPowerFxFunction(PowerFxConfig config, ITestInfraFunctions testInfraFunctions, ITestWebProvider testWebProvider, ISingleTestInstanceState singleTestInstanceState, ITestState testState, IFileSystem fileSystem)
2535
{
36+
// Initialize the read-only property from YAML via TestState
37+
var testSettings = testState?.GetTestSettings();
38+
IsPreviewNamespaceEnabled = testSettings?.ExtensionModules?.AllowPowerFxNamespaces?.Contains("Preview") == true;
39+
2640
ILogger logger = singleTestInstanceState.GetLogger();
27-
config.AddFunction(new PauseFunction(testInfraFunctions, testState, logger));
28-
logger.LogInformation("Registered Pause()");
41+
// Pass this PauseModule instance to PauseFunction so it can check IsPreviewNamespaceEnabled
42+
config.AddFunction(new PauseFunction(testInfraFunctions, testState, logger, this));
43+
logger.LogInformation($"Registered Pause() with Preview namespace enabled: {IsPreviewNamespaceEnabled}");
2944
}
3045

3146
public async Task RegisterNetworkRoute(ITestState state, ISingleTestInstanceState singleTestInstanceState, IFileSystem fileSystem, IPage Page, NetworkRequestMock mock)

0 commit comments

Comments
 (0)